Re: [GENERAL] Floating point error

From: Florian Weimer <fweimer(at)redhat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Maciek Sakrejda <m(dot)sakrejda(at)gmail(dot)com>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, Daniel Farina *EXTERN* <daniel(at)heroku(dot)com>, Tom Duffey *EXTERN* <tduffey(at)trillitech(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GENERAL] Floating point error
Date: 2013-03-06 14:24:46
Message-ID: 513751AE.9060301@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 03/05/2013 07:23 PM, Tom Lane wrote:
> Maciek Sakrejda <m(dot)sakrejda(at)gmail(dot)com> writes:
>> Thank you: I think this is what I was missing, and what wasn't clear
>> from the proposed doc patch. But then how can pg_dump assume that it's
>> always safe to set extra_float_digits = 3?
>
> It's been proven (don't have a link handy, but the paper is at least
> a dozen years old) that 3 extra digits are sufficient to accurately
> reconstruct any IEEE single or double float value, given properly
> written conversion functions in libc. So that's where that number comes
> from. Now, if either end is not using IEEE floats, you may or may not
> get equivalent results --- but it's pretty hard to make any guarantees
> at all in such a case.

There's also gdtoa, which returns the shortest decimal representation
which rounds to the same decimal number. It would print 0.1 as 0.1, but
0.1 + 0.2 as 0.30000000000000004.

--
Florian Weimer / Red Hat Product Security Team

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shaun Thomas 2013-03-06 14:35:17 Re: Why does slony use a cursor? Anyone know?
Previous Message Alexander Farber 2013-03-06 14:14:43 Re: Finding matching words in a word game

Browse pgsql-hackers by date

  From Date Subject
Next Message Joachim Wieland 2013-03-06 14:32:10 Re: Optimizing pglz compressor
Previous Message Tom Lane 2013-03-06 14:16:59 Re: Materialized views WIP patch