Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754

From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Thomas Munro <munro(at)ip9(dot)org>
Cc: Hannu Krosing <hannu(at)2ndquadrant(dot)com>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754
Date: 2012-10-28 10:37:41
Message-ID: 508D0AF5.9010000@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 10/28/2012 11:21 AM, Thomas Munro wrote:
> On 28 October 2012 09:43, Hannu Krosing <hannu(at)2ndquadrant(dot)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
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2012-10-28 10:54:11 Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754
Previous Message Hannu Krosing 2012-10-28 10:34:28 Re: Should "select 'nan'::float = 'nan'::float;" return false as per IEEE 754