Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mC2VK-0008Pg-8G for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Aug 2021 16:15:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mC2VJ-0007j9-3z for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Aug 2021 16:15:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mC2VI-0007j1-SP for pgsql-hackers@lists.postgresql.org; Fri, 06 Aug 2021 16:15:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mC2VE-0004Oi-VB for pgsql-hackers@lists.postgresql.org; Fri, 06 Aug 2021 16:15:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 176GFIa42492412; Fri, 6 Aug 2021 12:15:18 -0400 From: Tom Lane To: Dean Rasheed cc: Yugo NAGATA , PostgreSQL Hackers , Dave Page Subject: Re: Numeric x^y for negative x In-reply-to: References: <20210720181509.51a037ed0a8cb0f6d3ffda3a@sraoss.co.jp> <20210722141136.573c11dfc06f4dd46b661bca@sraoss.co.jp> <2394813.1628179479@sss.pgh.pa.us> <2449471.1628218684@sss.pgh.pa.us> Comments: In-reply-to Dean Rasheed message dated "Fri, 06 Aug 2021 17:06:20 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2492410.1628266518.1@sss.pgh.pa.us> Date: Fri, 06 Aug 2021 12:15:18 -0400 Message-ID: <2492411.1628266518@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dean Rasheed writes: > So the "test for overflow by reverse-conversion" obviously isn't > working as intended, and it's going through power_var_int() when it > shouldn't. I don't think there's anything wrong with that code, so I > think this is a compiler bug. Yeah, looks like one. > I guess the best thing to do is just test the value against > PG_INT32_MIN/MAX, which is what int84() does. There are 2 other places > in numeric.c that use similar code to check for int16/32 overflow, so > it's possible that they're broken in the same way on that platform, > but they aren't covered by the regression tests, so it's also possible > that they're OK. Anyway, something like the attached seems likely to > be safer. Looks plausible by eyeball (I've not tested). regards, tom lane