pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jarosław Stokłosa <jaroslaw.stoklosa@nomino.pl>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: John McKown <john.archie.mckown@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14046: Bad mathematical rules for 0 cast
Date: Thu, 31 Mar 2016 09:59:50 +0200
Message-ID: <56FCD8F6.8090805@nomino.pl> (raw)
In-Reply-To: <CAKFQuwbmR06hJZ5CEZbUPsMXP_KP0rOo=9n=UPX8XTsmk9vtCg@mail.gmail.com>
References: <20160325085614.2915.72425@wrigleys.postgresql.org>
	<CAAJSdjhfjrtzPjtNbf=qGeD1o+cwxfYLo_9nB2_AsVODQB7Gog@mail.gmail.com>
	<56FB7853.5090803@nomino.pl>
	<CAKFQuwbmR06hJZ5CEZbUPsMXP_KP0rOo=9n=UPX8XTsmk9vtCg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

W dniu 30/03/2016 o 18:03, David G. Johnston pisze:
> On Tue, Mar 29, 2016 at 11:55 PM, Jarosław Stokłosa 
> <jaroslaw.stoklosa@nomino.pl <mailto:jaroslaw.stoklosa@nomino.pl>>wrote:
>
>
>     W dniu 25/03/2016 o 14:32, John McKown pisze:
>>     On Fri, Mar 25, 2016 at 3:56 AM, <jaroslaw.stoklosa@nomino.pl
>>     <mailto:jaroslaw.stoklosa@nomino.pl>>wrote:
>>
>>         The following bug has been logged on the website:
>>
>>         Bug reference:      14046
>>         Logged by:          Jarosław Stokłosa
>>         Email address: jaroslaw.stoklosa@nomino.pl
>>         <mailto:jaroslaw.stoklosa@nomino.pl>
>>         PostgreSQL version: 9.4.5
>>         Operating system:    x86_64-redhat-linux-gnu
>>         Description:
>>
>>         Below query should return 2 times TRUE.
>>
>>         SELECT cast('+0' as FLOAT) = cast('-0' as FLOAT), cast('+0'
>>         as FLOAT)::TEXT
>>         = cast('-0' as FLOAT)::TEXT
>>
>>         +0 and -0 should be casted to +0 or 0.
>>
>
> ​How would you propose to implement this "or"?​
>

I propose for TEXT cast '-0'::FLOAT and '+0'::FLOAT to '0'::TEXT - like 
'-0'::NUMERIC::TEXT,  '+0'::NUMERIC::TEXT




>>
>>     ​ I humbly disagree with you. PostgreSQL use IEEE 754 for
>>     floating point (mainly because that is what most - not all -
>>     computers today use). IEEE 754 distinguishes +0 (or just 0) from
>>     -0. cast('-0' as FLOAT) results in an IEEE 754 negative zero.
>>     Which is not identically equal to a positive zero. The case to
>>     TEXT should, and does, preserve this non-identical difference. ​
>
>     I'm disagee with you. PostgreSQL don't distinguish +0 from -0
>     because cast('+0' as FLOAT) = cast('-0' as FLOAT) equals to TRUE.
>     This is math rules. So case to float then to text shoud, and
>     doesn't, preserve the equality. IEEE754 describes storage numbers
>     in computer's memory but doesn't turn off math comparation rules.
>
>
> Agreed. It is the cast to text turns off math comparison rules.
>
>
I understand, that convert to text can produce trouble with comparation 
- Tom Lane give example in this thread, but in this case IEEE 754 
doesn't prohibit to show zero without sign. NUMERIC is an example.

Regards
Jarek Stokłosa

view thread (10+ messages)  latest in thread

Message-ID: <56FCD8F6.8090805@nomino.pl>
Permalink:  ../56FCD8F6.8090805@nomino.pl/
Also on:    postgresql.org/message-id/56FCD8F6.8090805@nomino.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: jaroslaw.stoklosa@nomino.pl, david.g.johnston@gmail.com, john.archie.mckown@gmail.com
  Subject: Re: BUG #14046: Bad mathematical rules for 0 cast
  In-Reply-To: <56FCD8F6.8090805@nomino.pl>
  References: <20160325085614.2915.72425@wrigleys.postgresql.org> <CAAJSdjhfjrtzPjtNbf=qGeD1o+cwxfYLo_9nB2_AsVODQB7Gog@mail.gmail.com> <56FB7853.5090803@nomino.pl> <CAKFQuwbmR06hJZ5CEZbUPsMXP_KP0rOo=9n=UPX8XTsmk9vtCg@mail.gmail.com> <56FCD8F6.8090805@nomino.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox