mpf_t and mpf_get_str

Carlos Carreras carreras at die.upm.es
Mon Nov 19 17:04:56 CET 2007


Hi Torbjorn, and thanks for your message and for your time.

On Mon, 2007-11-19 at 14:57 +0100, Torbjorn Granlund wrote:
> Your assumption that the mantissas are the same is not correct.

Why not? Aren't mantissas stored in binary? Doesn't mpf_get_str provide
all the available bits when using base 2? How can they be different?

> 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.

I agree with that, but I understand that mpf stores the mantissa in
binary, so I'd say that two mpf with identical binary mantissas should
provide identical outputs in any base, since such outputs are generated
from the same bits. Of course, I am assuming that mpf_get_str provides
all the mantissa bits when using base 2 (at least this is what I
understand from the manual).

> 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.

I am not expecting to restore the original value.

> 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.

I agree, as long as convertion routines are used (i.e. base is different
from 2), but if numbers are stored in binary, no convertion routines
should be needed.

Carlos
Hi Torbjorn, and thanks for your message and for your time.

On Mon, 2007-11-19 at 14:57 +0100, Torbjorn Granlund wrote:
> Your assumption that the mantissas are the same is not correct.

Why not? Aren't mantissas stored in binary? Doesn't mpf_get_str provide
all the available bits when using base 2? How can they be different?

> 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.

I agree with that, but I understand that mpf stores the mantissa in
binary, so I'd say that two mpf with identical binary mantissas should
provide identical outputs in any base, since such outputs are generated
from the same bits. Of course, I am assuming that mpf_get_str provides
all the mantissa bits when using base 2 (at least this is what I
understand from the manual).

> 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.

I am not expecting to restore the original value.

> 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.

I agree, as long as convertion routines are used (i.e. base is different
from 2), but if numbers are stored in binary, no convertion routines
should be needed.

Carlos




More information about the gmp-discuss mailing list