Re: float4 problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Doug McNaught <doug(at)mcnaught(dot)org>
Cc: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: float4 problem
Date: 2002-11-20 17:42:49
Message-ID: 11178.1037814169@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Doug McNaught <doug(at)mcnaught(dot)org> writes:
> Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> writes:
>> May be I miss something, but seems there is a problem with float4
>> in 7.2.3 and 7.3RC1 (6.53 works fine):
>>
>> test=# create table t ( a float4);
>> CREATE TABLE
>> test=# insert into t values (0.1);
>> INSERT 32789 1
>> test=# select * from t where a=0.1;
>> a
>> ---
>> (0 rows)

> I'm guessing this is because 0.1 is not directly representable as a
> binary floating point number, and literal floating constants are
> float8 not float4, and 0.1::float4 != 0.1::float8.

Right.

I think that this particular form of the problem will go away in 7.4.
Currently, "a = 0.1" is resolved as float4=float8, and there's no way
for the float4 approximation of 0.1 to exactly equal the float8
approximation of it. However, if we eliminate cross-datatype
comparison operators as I've proposed, the comparison should be resolved
as float4 = float4 and it would work.

Nonetheless, expecting exact equality tests to succeed with float values
is generally folly. I really do not believe the claim that this worked
in 6.5.3.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2002-11-20 17:48:15 Re: Geometry test on NetBSD (was Re: [HACKERS] RC1?)
Previous Message Ken Hirsch 2002-11-20 17:02:38 Re: Geometry test on NetBSD (was Re: [HACKERS] RC1?)