Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1alIKJ-0002nt-Ts for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Mar 2016 15:46:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1alIKJ-0000Ln-GT for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Mar 2016 15:46:35 +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 1alA2X-0001rG-Mp for pgsql-bugs@postgresql.org; Wed, 30 Mar 2016 06:55:41 +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 1alA2U-00089f-5i for pgsql-bugs@postgresql.org; Wed, 30 Mar 2016 06:55:40 +0000 Received: from localhost (localhost [127.0.0.1]) by mailgw2.gradier.pl (Postfix) with ESMTP id 96DE55FF03; Wed, 30 Mar 2016 08:55:19 +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 JAm65yc7ta2y; Wed, 30 Mar 2016 08:55:19 +0200 (CEST) Subject: Re: BUG #14046: Bad mathematical rules for 0 cast To: John McKown References: <20160325085614.2915.72425@wrigleys.postgresql.org> Cc: pgsql-bugs@postgresql.org From: =?UTF-8?Q?Jaros=c5=82aw_Stok=c5=82osa?= Message-ID: <56FB7853.5090803@nomino.pl> Date: Wed, 30 Mar 2016 08:55:15 +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="------------020601050905010807020803" 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. --------------020601050905010807020803 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. > > > ​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. ​ > > Hi, 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. Regards Jarek Stokłosa --------------020601050905010807020803 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
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.

​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. ​

 

Hi,

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.

Regards
Jarek Stokłosa

--------------020601050905010807020803--