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 1oAvfc-0007bX-RX for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Jul 2022 15:50:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oAvfb-000740-Fn for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Jul 2022 15:49:59 +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 1oAvfb-00073r-7p for pgsql-bugs@lists.postgresql.org; Mon, 11 Jul 2022 15:49:59 +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 1oAvfU-0007Im-St for pgsql-bugs@lists.postgresql.org; Mon, 11 Jul 2022 15:49:58 +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 26BFnnhn1119194; Mon, 11 Jul 2022 11:49:50 -0400 From: Tom Lane To: su.sinodan@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17546: power() function - value is distorted via automatic type cast In-reply-to: <17546-d71fe78a505f9f7b@postgresql.org> References: <17546-d71fe78a505f9f7b@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 11 Jul 2022 15:20:21 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1119192.1657554589.1@sss.pgh.pa.us> Date: Mon, 11 Jul 2022 11:49:49 -0400 Message-ID: <1119193.1657554589@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > When a certain number (p, s) with a fractional part (specific examples - > 1.11 and 69.96) is multiplied by a power (10, N), the resulting value is > distorted. > However, if the power(10, N) is manually converted to an integer, the > resulting value is correct. > It looks like there is some kind of problem with the automatic type > conversion of the power() function. Your query is invoking the float8 variant of power(), which is necessarily of limited precision. If I change "w.degree::integer" to "w.degree::numeric", then it invokes the numeric variant of power(), and I get correctly rounded results (much more slowly unfortunately :-(). So I don't see any bug here. It might be surprising that the parser prefers float8 over numeric when the given function arguments don't exactly match either one. But that's a very ancient decision that we're not going to change. There is support for it in the SQL standard, which directs implementations to prefer inexact numeric types over exact ones when they have to make a choice. regards, tom lane