[freetds] patch: corrects the reading of large integer valueswhen represented as double

Jose Luu jluu at applia.fr
Wed May 19 14:05:56 EDT 2004


 James,

>
> IIRC, double precision is good only for 15 positions.  Frediano once
> showed me how to examine the bit pattern, to know how precisely a number
> can be so represented.  I'd like to be convinced that your 16th position
> is significant.
>

Here is the test case:

#include <stdio.h>

main()
{
double n=9000000000000010.0;
printf("%.16g\n",n);
n=n+1;
printf("%.16g\n",n);
printf("%.15g\n",n);
}

and output:

9000000000000010
9000000000000011
9.00000000000001e+15

9e+15 is about the upper limit (try with 9100000000000010.0), therefore not
all 16 digit numbers can be represented, this is why 15 digit is remembered
as the "correct" value. However as you can see for the 16 digit numbers that
can be represented by a double, expressing then using 15 digits only leads
to information loss.

Jose

PS: the exact upper limit is a pattern of all ones in the mantissa ie
(2^53-1) that is 9007199254740991 (53 corresponding to the 52 bit mantissa +
the hidden bit).





More information about the FreeTDS mailing list