Interface of mpf_get_str
wilco at oelen.net
wilco at oelen.net
Thu Jan 28 23:10:31 CET 2010
Hello,
I run into a problem with using the mpf_get_str() function of the GMP
package. This is not a real bug report, it is a comment on this interface.
The problem described here can only be solved by modifying the interface,
provided by this function.
Suppose I am working on a 32-bit platform and the limb size is 32 bits and
the exponent size also is 32 bits (signed), then the maximum exponent is
2^31-1 and the maximum representable number will be something like
D^(2^31), where D is the base, used in GMP (for most 32 bit architectures
I assume D = 2^32). This allows numbers to be represented as big as
2^(2^36).
Now, if I want to write such a number in decimal form, then the exp
argument (second argument) of the mpf_get_str() function cannot hold the
exponent. In decimal form, the maximum exponent can be
2^36*(log(2)/log(10)), which still is much larger than can fit in a 32 bit
signed integer. So, the mpf_get_str() function only can work properly for
numbers which have a sufficiently small exponent. The exponent of really
big numbers (and also numbers having very low magnitude) cannot be decoded
with this function.
A similar problem exists for 64-bit architectures. Here, the maximum
representable value is as big as 2^(2^69) and for bases in the range 2 ...
62 again the exponent of really huge numbers cannot be decoded properly
using mpf_get_str().
When mpf_get_str() is called for really big numbers, then this funtion
gives bogus results for the exponent. This problem can easily be
reproduced by making a small program which computes (10.0^(10^10)), which
can be represented on a 32 bit platform with 32 bit limbs. Then call
mpf_get_str() on this number, using base 10. A bogus exponent is returned,
or the program crashes.
I hope this comment helps a little bit, I just wanted to let you know of
this.
Regards,
Wilco
More information about the gmp-bugs
mailing list