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.96) (envelope-from ) id 1wHMds-0076ai-20 for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Apr 2026 14:08:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wHMdq-00E5eq-2i for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Apr 2026 14:08:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wHMdq-00E5eh-1G for pgsql-bugs@lists.postgresql.org; Mon, 27 Apr 2026 14:08:54 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wHMdn-000000032SS-07UF for pgsql-bugs@lists.postgresql.org; Mon, 27 Apr 2026 14:08:53 +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 63RE8bvt2566491; Mon, 27 Apr 2026 10:08:37 -0400 From: Tom Lane To: John Naylor cc: fmusqlgen@163.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19467: Inconsistency in MOD() result involving POWER() and floating-point precision in PostgreSQL In-reply-to: References: <19467-b75f37ccc0b69261@postgresql.org> Comments: In-reply-to John Naylor message dated "Mon, 27 Apr 2026 19:20:21 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2566489.1777298917.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 27 Apr 2026 10:08:37 -0400 Message-ID: <2566490.1777298917@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk John Naylor writes: > On Mon, Apr 27, 2026 at 6:33 PM PG Bug reporting form > wrote: >> Mathematically, this corresponds to the fractional part of 3^70.31, which >> should be deterministic for a given evaluation strategy. >> >> However, different systems produce significantly different results: > These two statements don't contradict eachother. > Trying the expression on WolframAlpha shows 0.41 is close to the > expected value, so I don't see a bug here. Those other systems are probably using float8 arithmetic, which has nowhere near enough precision to give a nonzero answer. In Postgres, constants like "3.00" are type numeric not type float8, so: regression=# select pow(3.00, 70.31); pow --------------------------------------- 3518806773889710662003177340498520.41 (1 row) regression=# select mod(pow(3.00, 70.31), 1); mod ------ 0.41 (1 row) You can duplicate the lower-precision answer if you want: regression=# select pow(3.00::float8, 70.31::float8); pow ------------------------ 3.5188067738897196e+33 (1 row) regression=# select pow(3.00::float8, 70.31::float8)::numeric; pow ------------------------------------ 3518806773889720000000000000000000 (1 row) regression=# select mod(pow(3.00::float8, 70.31::float8)::numeric, 1); mod ----- 0 (1 row) regards, tom lane