possible bug in mpz_cmp_d

Emmanuel Thomé Emmanuel.Thome at inria.fr
Tue Jul 10 09:28:24 UTC 2018


err, yes. of course you're right, it's 53 not 56. Too many 6's here, I
guess. Well, anyway, 61 is too much.

E.

On Tue, Jul 10, 2018 at 10:46:27AM +0200, Paul Zimmermann wrote:
> > 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