float8 strtod weirdness - Mailing list pgsql-hackers

From Nikhil Sontakke
Subject float8 strtod weirdness
Date
Msg-id a301bfd90901070642g6a483818g50f2ca563f965001@mail.gmail.com
Whole thread Raw
Responses Re: float8 strtod weirdness  (David Fetter <david@fetter.org>)
Re: float8 strtod weirdness  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: float8 strtod weirdness  (Kenneth Marshall <ktm@rice.edu>)
List pgsql-hackers
Hi, <br /><br />Consider the following with latest CVS sources:<br /><br />postgres=# create table temp(val float4);<br
/>CREATETABLE<br />postgres=# insert into temp values (415.1);<br />INSERT 0 1<br />postgres=# select * from temp where
val= 415.1;<br />  val<br />-----<br />(0 rows)<br /><br />!?<br /><br />The reason seems to be that 415.1 ends up
beingtreated as a numeric and is converted into float8 (why not float4? - it could have helped to use the float4eq
functionthen) <br clear="all" /><br />The float8in function uses strtod which for some reason converts '415.1' into
415.10000000000002causing 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 :)<br /><br />Casting
tofloat4 works as expected:<br />postgres=# select * from rel where x = 415.1::float4;<br />   x<br />-------<br
/> 415.1<br/>(1 row)<br /><br />Regards,<br /> Nikhils<br />-- <br /><a href="http://www.enterprisedb.com"
target="_blank">http://www.enterprisedb.com</a><br/> 

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Multiplexing SUGUSR1
Next
From: David Fetter
Date:
Subject: Re: float8 strtod weirdness