Skip to Content.
Sympa Menu

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

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Jose Luu" <jluu AT applia.fr>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] patch: corrects the reading of large integer valueswhen represented as double
  • Date: Wed, 19 May 2004 20:05:56 +0200

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).






Archive powered by MHonArc 2.6.24.

Top of Page