bug-gmp
[Top][All Lists]
Advanced

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

Re: mpf_get_str trouble


From: Paul Zimmermann
Subject: Re: mpf_get_str trouble
Date: Tue, 17 Dec 2002 11:36:07 +0100

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

   int main() {

           mpf_t number ;
           mp_exp_t exponent ;
           char *word ;

           mpf_init(number) ;

           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.0000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   000000000020589962369524017340100000000000000000000000000000000000000000
   000000000000000000000000000000000000000000000000000000000000000000000000
   00000000000000000000000000000000000000000000000000000000000
   exponent = -257

The trouble seems to be in gmp_printf, not in mpf_get_str, since
1/5.0^365/365 is .2058996237E-257, so the exponent -257 is correct.
But gmp_printf prints 512 zeros intead of 257 between the decimal
point and the first non zero digit. The "extra" 255 digits explain
why 705 digits are printed instead of the 450 requested.

Paul



reply via email to

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