mpf_integer_p() bug

Paul Zimmermann Paul.Zimmermann at loria.fr
Mon Feb 18 10:49:51 CET 2008


> > For instance, performing 35.0/1.4,
> 
> That's not possible: 1.4 is not exactly representable in base 2
> (the base GMP uses). There's even a paragraph about that in the
> GMP documentation. No bug.

yes it is a very common mistake (it also occurred to me) to think that
mpf_init_set_d(index_f, 1.1) will set index_f to 1.1! As Vincent says,
1.1 is not exactly representable in radix 2 (whatever the precision).

One might argue that 5.0 is exactly representable, thus 35.0/5.0 should
be detected as an integer. However due to accumulated rounding errors,
the value of index_f is not exactly 5 at this point, at least this is
what mpf_out_str (stdout, 2, 0, index_f) says:

index_f=0.1010000000000000000000000000000000000000000000000000001011e3

If you initialize index_f with 5.0 instead of 1.1, then the first test
will succeed:

Dividing by 5.0, is the result an integer?  1

Paul Zimmermann


More information about the gmp-bugs mailing list