mpf_get_str trouble

Cesar Delgado beettlle@hotmail.com
Tue, 17 Dec 2002 03:39:23 +0000


I'm writing a program and it's not quite working.  I have finaly narrowed it 
down to the mpf_get_str function.  I wrote a little program to show what is 
happening.  I'm running GMP 4.0 from the RPM that comes with RH7.2, but I 
see the same behaviour under RH8.0 and the GMP RPM that comes with the 
distro.

This program:

#include <stdio.h>
#include <gmp.h>

int main() {

        mpf_t number ;
        mp_exp_t exponent ;
        char *word ;

        mpf_init(number) ;
        mpf_init(one) ;

        mpf_set_ui(number, 1) ;
        mpf_div_ui(number, number, 5) ;
        mpf_pow_ui(number, number, 363) ;
        mpf_div_ui(number, number, 363) ;

        gmp_printf("%1.*Ff\n", 450, number) ;
        word = mpf_get_str(NULL, &exponent, 10, 0, number) ;
        printf("exponent = %li\n", (long int)exponent) ;
}

outputs :

0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000051758514220910925132500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
exponent = -256

But when I change the value of the power and the division to the next odd 
number, like so:

#include <stdio.h>
#include <gmp.h>

int main() {

        mpf_t number ;
        mp_exp_t exponent ;
        char *word ;

        mpf_init(number) ;
        mpf_init(one) ;

        mpf_set_ui(number, 1) ;
        mpf_div_ui(number, number, 5) ;
        mpf_pow_ui(number, number, 365) ;
        mpf_div_ui(number, number, 365) ;

        gmp_printf("%1.*Ff\n", 450, number) ;
        word = mpf_get_str(NULL, &exponent, 10, 0, number) ;
        printf("exponent = %li\n", (long int)exponent) ;
}

I get:

0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002058996236952401734010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
exponent = -257

The exponents produced by the second program just doesn't make sence and I 
can't figure out what I'm doing wrong.

Any help is greatly apreceated.

Thanks,

-Cesar

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail