float8 strtod weirdness

From: "Nikhil Sontakke" <nikhil(dot)sontakke(at)enterprisedb(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: float8 strtod weirdness
Date: 2009-01-07 14:42:44
Message-ID: a301bfd90901070642g6a483818g50f2ca563f965001@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Consider the following with latest CVS sources:

postgres=# create table temp(val float4);
CREATE TABLE
postgres=# insert into temp values (415.1);
INSERT 0 1
postgres=# select * from temp where val = 415.1;
val
-----
(0 rows)

!?

The reason seems to be that 415.1 ends up being treated as a numeric and is
converted into float8 (why not float4? - it could have helped to use the
float4eq function then)

The float8in function uses strtod which for some reason converts '415.1'
into 415.10000000000002 causing the subsequent comparison to fail. I guess
there are ample cases of float/strtod weirdness around? Needless to mention,
I was mighty surprised on seeing the output for the first time around :)

Casting to float4 works as expected:
postgres=# select * from rel where x = 415.1::float4;
x
-------
415.1
(1 row)

Regards,
Nikhils
--
http://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-01-07 14:44:09 Re: reducing statistics write overhead
Previous Message Stephen Frost 2009-01-07 14:16:30 Re: New patch for Column-level privileges