Re: Re: [GENERAL] Trouble with float4 afterupgrading from 6.5.3 to 7.0.2 - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: Re: [GENERAL] Trouble with float4 afterupgrading from 6.5.3 to 7.0.2
Date
Msg-id 398EE00B.772F181E@alumni.caltech.edu
Whole thread Raw
In response to Re: Re: [GENERAL] Trouble with float4 after upgrading from 6.5.3 to 7.0.2  (Philip Warner <pjw@rhyme.com.au>)
Responses Re: Re: [GENERAL] Trouble with float4 afterupgrading from 6.5.3 to 7.0.2  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-hackers
> I would have expected the latter to be at worst 10.10000000000000 +/-
> .00000000000001.
> Am I missing something?

Well, yes :)

10.1 can't be represented exactly, so the float8 representation has bits
set way down at the low end of the mantissa. When converting to float4
those low bits get rounded up or down into the lowest bit of the float4
representation. At that point, you have lost knowledge that this ever
was supposed to be *exactly* 10.1. And when converting back to float8,
that float4 low bit becomes a middle-range bit in the float8
representation, with all the bits underneath that zeroed.

Back in the old days, before printf() implementations settled down, you
would be reminded of this any time you did anything, since just
assigning 10.1 and then printing it out would give you some goofy
10.099999999998 or 10.10000000001 (don't count the number of digits here
too closely, they are only qualitatively correct).

                    - Thomas

pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: Re: [GENERAL] Trouble with float4 after upgrading from 6.5.3 to 7.0.2
Next
From: Tom Lane
Date:
Subject: Re: Re: [GENERAL] Trouble with float4 after upgrading from 6.5.3 to 7.0.2