Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754 - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754
Date
Msg-id 508D0AF5.9010000@2ndQuadrant.com
Whole thread Raw
In response to Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754  (Thomas Munro <munro@ip9.org>)
Responses Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754  (Thomas Munro <munro@ip9.org>)
List pgsql-hackers
On 10/28/2012 11:21 AM, Thomas Munro wrote:
> On 28 October 2012 09:43, Hannu Krosing <hannu@2ndquadrant.com> wrote:
>> This is how PostgreSQL currently works -
>>
>> test=# select 'NaN'::float = 'NaN'::float as must_be_false;
>>   must_be_false
>> ----------
>>   t
>> (1 row)
>>
>> I think that PostgreSQL's behaviour of comparing two
>> NaN-s as equal is wrong and Iwe should follow the IEEE 754 spec here
>>
>> As per IEEE 754 a NaN behaves similar to NULL in SQL.
> FWIW there is a note in the documentation about this:
>
> "Note: IEEE754 specifies that NaN should not compare equal to any
> other floating-point value (including NaN). In order to allow
> floating-point values to be sorted and used in tree-based indexes,
> PostgreSQL treats NaN values as equal, and greater than all non-NaN
> values."
I wonder how hard it would be to start treating NaNs as NULLs
so you could say ORDER BY fvalue NULLS AND NANS LAST :)

Hannu
>




pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754
Next
From: Thomas Munro
Date:
Subject: Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754