Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gQM54-0003Lg-C8 for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Nov 2018 00:45:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gQM52-0005ZY-P9 for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Nov 2018 00:45:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gQM52-0005ZR-EN for pgsql-bugs@lists.postgresql.org; Sat, 24 Nov 2018 00:45:52 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gQM4u-0005wL-LA for pgsql-bugs@lists.postgresql.org; Sat, 24 Nov 2018 00:45:51 +0000 Received: from [192.168.127.1] (port=52288 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gQM4p-000DFp-79; Sat, 24 Nov 2018 00:45:39 +0000 Received: from [127.0.0.1] (port=13883 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gQM4o-00010D-CN; Sat, 24 Nov 2018 00:45:38 +0000 From: Andrew Gierth To: Tom Lane Cc: victor@magic.io, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error In-Reply-To: <15115.1543017152@sss.pgh.pa.us> (Tom Lane's message of "Fri, 23 Nov 2018 18:52:32 -0500") Message-ID: <87va4nqr1a.fsf@news-spur.riddles.org.uk> References: <15519-4fc785b483201ff1@postgresql.org> <874lc7sb1a.fsf@news-spur.riddles.org.uk> <13162.1543014227@sss.pgh.pa.us> <87zhtzqs9o.fsf@news-spur.riddles.org.uk> <15115.1543017152@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sat, 24 Nov 2018 00:45:38 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: Tom> if (unlikely(num < (float4) INT_MIN || num >= (float4) INT_MAX || isnan(num))) >> if (num < (float4)INT_MIN || num >= -(float4)INT_MIN || ... Tom> Meh. Seems to me that's relying on pretty much the same Tom> assumptions No, because we know that INT_MIN is always exactly representable as a float (whereas INT_MAX is not), and therefore the cast result will not depend on any rounding choices whether at compile or run time. Nor does it depend on knowing that float4 can't represent INT_MAX exactly. -- Andrew (irc:RhodiumToad)