Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1allRJ-0000aG-3H for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Mar 2016 22:51:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1allRI-0000Uj-MQ for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Mar 2016 22:51:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ald7L-00087k-R6 for pgsql-bugs@postgresql.org; Thu, 31 Mar 2016 13:58:35 +0000 Received: from mailgw2.gradier.pl ([91.223.72.17]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ald7I-0005MV-5C for pgsql-bugs@postgresql.org; Thu, 31 Mar 2016 13:58:34 +0000 Received: from localhost (localhost [127.0.0.1]) by mailgw2.gradier.pl (Postfix) with ESMTP id 040A45FEFC; Thu, 31 Mar 2016 15:58:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at gradier.net.pl Received: from mailgw2.gradier.pl ([127.0.0.1]) by localhost (mailgw2.gradier.pl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id UOxRqdqU-E7R; Thu, 31 Mar 2016 15:58:12 +0200 (CEST) Subject: Re: BUG #14046: Bad mathematical rules for 0 cast To: "David G. Johnston" , tgl@sss.pgh.pa.us References: <20160325085614.2915.72425@wrigleys.postgresql.org> <56FB7853.5090803@nomino.pl> Cc: John McKown , "pgsql-bugs@postgresql.org" From: =?UTF-8?Q?Jaros=c5=82aw_Stok=c5=82osa?= Message-ID: <56FD2CE9.3050306@nomino.pl> Date: Thu, 31 Mar 2016 15:58:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------050201090003090503020900" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------050201090003090503020900 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 > >wrote: > > > W dniu 25/03/2016 o 14:32, John McKown pisze: >> On Fri, Mar 25, 2016 at 3:56 AM, > >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 >> >> 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 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. > > David J. Hi David, Tom, John, Solution for me: SELECT cast('+0' as FLOAT) = cast('-0' as FLOAT), cast('+0' as FLOAT)::NUMERIC::FLOAT::TEXT= cast('-0' as FLOAT)::NUMERIC::FLOAT::TEXT There are 2 times TRUE. Thank you for your opinion and objective discussion. Regards Jarek --------------050201090003090503020900 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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> 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> 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
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 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.

David J.

Hi David, Tom, John,

Solution for me:
SELECT cast('+0' as FLOAT) = cast('-0' as FLOAT), cast('+0' as FLOAT)::NUMERIC::FLOAT::TEXT= cast('-0' as FLOAT)::NUMERIC::FLOAT::TEXT

There are 2 times TRUE.

 Thank you for your opinion and objective discussion.

Regards
Jarek
--------------050201090003090503020900--