Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFc30-00EJB8-Qi for pgsql-sql@arkaria.postgresql.org; Mon, 25 Nov 2024 16:34:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tFc2z-00GRZv-Gs for pgsql-sql@arkaria.postgresql.org; Mon, 25 Nov 2024 16:34:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFc2z-00GRZn-7m for pgsql-sql@lists.postgresql.org; Mon, 25 Nov 2024 16:34:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFc2s-003nTx-GQ for pgsql-sql@lists.postgresql.org; Mon, 25 Nov 2024 16:34:48 +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 4APGYcVl1352241; Mon, 25 Nov 2024 11:34:38 -0500 From: Tom Lane To: Erik Brandsberg cc: szy <598546998@qq.com>, pgsql-sql Subject: Re: Inconsistent results for division and multiplication operations In-reply-to: References: Comments: In-reply-to Erik Brandsberg message dated "Mon, 25 Nov 2024 10:53:38 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1352239.1732552478.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 25 Nov 2024 11:34:38 -0500 Message-ID: <1352240.1732552478@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Erik Brandsberg writes: > This is a common issue with using floating point math. You will see the > same issue with many systems. Basically, the order of operations can > trigger very minor differences in results, but if you round the first > result to the same number of significant digits as the input, it would b= e > identical. > https://learn.microsoft.com/en-us/office/troubleshoot/access/floating-ca= lculations-info Yeah. The OP is actually working with PG's "numeric" type, not floating-point, but the principle is the same. Some division results can't be represented exactly in any finite number of digits, so you get roundoff error. regards, tom lane