mpf_t and mpf_get_str
Torbjorn Granlund
tg at swox.com
Mon Nov 19 14:57:34 CET 2007
In the following code two mpf_t are initialized with two decimal
strings that are different in the last digit. Both strings produce the
same mantissa and exponent values in the mpf_t's (due to the base
conversion, I assume). However, the strange thing is that both mpf_t
(with identical binary mantissa and exponent as shown through printf)
then produce different decimal output strings. Am I doing something
wrong? Can anyone explain? Thanks.
Your assumption that the mantissas are the same is not correct.
With mpf, and often with plain double, printing a value in some base
cannot be used for determining equality. Numbers might print as the
same in one base, but not in another.
It would be desirable to make printing routines to generate unique
minimal strings for each value, and allow input routines to exactly
restore the original value. mpf does not provide that. I think glibc
does it for IEEE double, but most C libraries don't.
It would probably not be easy for fix mpf conversion routines to get
the desirable properties. Semantics of mpf aren't overly well-
specified, making the problem more difficult.
--
Torbjörn
More information about the gmp-discuss
mailing list