possible bug in mpz_cmp_d

paul zimmermann Paul.Zimmermann at inria.fr
Tue Jul 10 08:46:27 UTC 2018


> On Mon, Jul 09, 2018 at 11:04:57PM -0600, Tom Tromey wrote:
> [...]
> >       double d = -2305843009213693953.0;
> [...]
> > I expect this to print 0, because the numbers are the same, and because
> > the number can be exactly represented as a double.
> 
> I don't think so.
> 
> d is -(2^61+1). You only have 56 bits of mantissa in a double. No way you
> can tell apart -(2^61+1) and -(2^61+2). You would need a larger mantissa
> for that.

more precisely the literal -2305843009213693953.0 has 62 bits, and thus
cannot be represented exactly in a double, which (usually) has a significand
of 53 bits (IEEE 754 binary64).

If the rounding mode is to nearest-even, then the value -2^61 is put into d,
which is the closest representable value to the literal.

Best regards,
Paul


More information about the gmp-bugs mailing list