bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mpf_get_str trouble


From: Cesar Delgado
Subject: mpf_get_str trouble
Date: Mon, 16 Dec 2002 22:25:19 -0600

I sent this email to the users mailing list and was told to send it here.  If a better description of the problem is needed please don’t hesitate in contacting me and I will try to supply the needed information.

 

I'm writing a program and it's not quite working.  I have finally 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 on an x86 machine, but I see the same behavior 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) ;

}

 

output :

 

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 sense and I can't figure out what I'm doing wrong. 

 

Any help is greatly appreciated.

 

Thanks,

 

-Cesar Delgado

---------------------------------------------

Secure Distributed Information @ UNL
http://rcf.unl.edu
address@hidden, address@hidden

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]