float8 strtod weirdness
От | Nikhil Sontakke |
---|---|
Тема | float8 strtod weirdness |
Дата | |
Msg-id | a301bfd90901070642g6a483818g50f2ca563f965001@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: float8 strtod weirdness
Re: float8 strtod weirdness Re: float8 strtod weirdness |
Список | 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 по дате отправления: