Floating Point Arithmetic

Malcolm Kay malcolm.kay at internode.on.net
Fri Dec 3 05:41:21 PST 2004


On Fri, 3 Dec 2004 07:23 pm, Florian Hengstberger wrote:
> Hi!
>
> I tried to figure out the capability of double:
> so I calculated
>
> d=2**n (with a for-loop)
>
> increasing n step by step.
> Of course I get a floating point exception when
> d is bigger than 10**308.
> But what makes me wondering is the fact that printing
> printf("%lf",d) gives me the full range of numbers!
>
> Calculating 2**1000 and I got the correct number
> with all (!!) digits. (I cross-checked the digits with python.)
> This is unexpected because sizeof(double) on my machine is 8,
> and so I thought that the limit for the correct representation
> is 2**(8*8).
> (Actually the limit should be - meeting the IEEE standard -
> 2**52, the space reserved for representing the fraction of
> a floating point number.)
> Anyway I can calculate 2**n, with n up to 1023 exact.
> Why is this???

Just think about it. If you have an integer power of two all the
discarded significant bits were zero anyway so the representation 
is exact.

But try 2**1000-1

Malcolm




More information about the freebsd-questions mailing list