vincent at vinc17.org
Mon Feb 18 10:58:41 CET 2008
Also, in case anyone wonders...
On 2008-02-18 00:36:53 -0500, Fred wrote:
> Dividing by 2.5, is the result an integer? 0 (<-- should be > 0)
Of course, you should get > 1 because 2.5 is exactly representable.
But your program is incorrect:
> //Test program
> // Reads in argument 1, which is a number to divide constantly by another number which
> // is increased by .1 each go around up to sqrt(arg1).
0.1 is not exactly representable, hence the problem. This bug is very
similar to the well-known Patriot bug, that has caused the death of
28 American soldiers:
(also due to increments of an approximation of 0.1, as explained).
BTW, for multiple-precision binary FP arithmetic I suggest you use
MPFR, that provides correct rounding and can also output values so
that you can recover the original value by the inverse conversion.
This means that by doing that (i.e. do not restrict the number of
digits in the output), you'll see if the value is not an integer.
Vincent Lefèvre <vincent at vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
More information about the gmp-bugs