[BUG] Denormal float values break backup/restore

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [BUG] Denormal float values break backup/restore
Date: 2011-06-10 08:50:24
Message-ID: BANLkTi=Z6cT8c_j6YrXHcx=CkrxUMt6NBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi list,

I was playing around with denormal float values in response to the
Itanium thread and noticed that Postgres' float conversion functions
behave inconsistently, at least on Linux with glibc 2.14

It can successfully convert denormal float values to strings:
marti=# select '0.25e-307'::float8/2 as val;
val
-----------
1.25e-308

But trying to convert back to float fails:
marti=# select ('0.25e-307'::float8/2)::text::float8 as val;
ERROR: "1.25e-308" is out of range for type double precision

The most significant impact of this is that anyone who has these
values in their tables can't restore them from backup. I'm surprised
nobody has reported this yet, but it seems like worthy of fixing in
9.2 at least.

Looking at utils/adt/float.c, seems that some platforms also have
other problems with the strtod() function. Maybe it's time to
implement our own, without bugs and with proper handling for denormal
float values?

Also applies to float4s:
marti=# select ('1.40129846432481707e-45'::float4/4)::text::float4;
ERROR: value out of range: underflow

Another erratic behavior of float4in:
marti=# select ('1.40129846432481707e-45'::float4/2)::text;
text
----------------------
7.00649232162409e-46

marti=# select ('1.40129846432481707e-45'::float4/2)::text::float4;
float4
------------
1.4013e-45

Regards,
Marti

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Grzegorz Szpetkowski 2011-06-10 10:06:14 Feature idea: standard_quoting_identifiers property
Previous Message Florian Pflug 2011-06-10 08:47:49 Re: TG_DEPTH patch v1