Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1alJ2t-0004aC-HM for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Mar 2016 16:32:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1alJ2s-00030S-CD for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Mar 2016 16:32:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1alJ2r-0002xu-3K for pgsql-bugs@postgresql.org; Wed, 30 Mar 2016 16:32:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1alJ2m-0003wN-JL for pgsql-bugs@postgresql.org; Wed, 30 Mar 2016 16:32:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u2UGWBlY018629; Wed, 30 Mar 2016 12:32:12 -0400 From: Tom Lane To: =?UTF-8?Q?Jaros=c5=82aw_Stok=c5=82osa?= cc: John McKown , pgsql-bugs@postgresql.org Subject: Re: BUG #14046: Bad mathematical rules for 0 cast In-reply-to: <56FB7853.5090803@nomino.pl> References: <20160325085614.2915.72425@wrigleys.postgresql.org> <56FB7853.5090803@nomino.pl> Comments: In-reply-to =?UTF-8?Q?Jaros=c5=82aw_Stok=c5=82osa?= message dated "Wed, 30 Mar 2016 08:55:15 +0200" Date: Wed, 30 Mar 2016 12:32:11 -0400 Message-ID: <18628.1459355531@sss.pgh.pa.us> X-Pg-Spam-Score: -2.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 =?UTF-8?Q?Jaros=c5=82aw_Stok=c5=82osa?= writes: >> ​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. Sorry, but that argument isn't terribly convincing. The point is exactly whether casting to another type must preserve equality, and you're just asserting that it should be so without providing any compelling reason. There are plenty of other counterexamples to that, though. One that comes to mind is that 42::numeric(6,3) will compare equal to 42::numeric(6,0), but if you cast them to text you will get '42.000' and '42', which are not equal according to text's rules. Another is that 'FOO' and 'foo' compare equal according to citext, but if you cast them to text they aren't equal anymore. Basically, different types are allowed to have different equality behaviors. That's too useful to give up in the (vain) pursuit of somebody's notion of mathematical purity. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs