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.98.2) (envelope-from ) id 1xMgsg-000000029Tu-3Tsw for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:31 +0000 Received: from localhost ([127.0.0.1]:51180 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMgsf-00000008qJl-1zPJ for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:50756) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMJm3-000000031K8-2JIA for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:38:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMJm2-00000001UJH-01jL for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:38:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=SdzYMThMv8KnkEzFwdQ5UOBW5q2w+WcmgPEkzDHJ6HI=; b=pqRom5xRfesmd7kRg0z/Pl5Gy/ 5p/OVQKqpxGRhGoov7GcJVvCvED0JFN2MKaB9iWdePX2dkJLjS2+RF1sVUlmPntXnSySrHa9tmzJz 6RaWBAeBY3T2+5LGJn2S6zbp+FJI7N1n9I1LPB9p9Q3MjrqLJQTo+bpNFLVrLdJG4gA5hwjchOyjP Fp+aqA4IsTsV818RkMCaVYXPI0ZjEu0dMdTD/6s6g9xaE+4qxE04Y0MqTogDSyPNJ5EqVZHZX4Riv rBlOsjQOtOpuEFrdhCPoxmUaqWWbHaxFUnpw2N97dbKFz7JdfQjdHnG9rlIy7w5I+YtkVTx97k6cc 8s3l1zVQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMJm1-00000004Hge-0oot for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:38:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMJly-00000005c3J-4BWM for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 06:38:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Thu, 29 Oct 2026 06:37:56 +0000 Message-ID: <19811-3e5c60ea0ef2a9b7@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19811 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux x86_64 Description: =20 The two-argument numeric logarithm returns +Infinity for x =3D Infinity regardless of the base. For bases between 0 and 1 the correct result is -Infinity, and for base 1 the call should be rejected. Self-contained test (official postgres:latest docker image, 18.6): SELECT log('0.5'::numeric, '1e308'::numeric); -- -1023.15385322530760 (correct sign) SELECT log('0.5'::numeric, 'Infinity'::numeric); -- Infinity (wrong: should be -Infinity) SELECT log('0.1'::numeric, 'Infinity'::numeric); -- Infinity (wrong) SELECT log('0.25'::numeric, 'Infinity'::numeric); -- Infinity (wrong) Controls: SELECT log('2'::numeric, 'Infinity'::numeric); -- Infinity (correct, base > 1) SELECT ln('Infinity'::numeric); -- Infinity (correct) SELECT log('0.5'::numeric, '-Infinity'::numeric); -- ERROR: cannot take logarithm of a negative number The function is internally inconsistent: with a large finite argument the sign is correct (-1023 for 1e308, since ln(x)/ln(0.5) is negative), but at exactly Infinity the sign flips to positive. Mathematically log_b(Infinity) =3D ln(Infinity)/ln(b) =3D Infinity/ln(b), which is -Infinity for 0 < b < 1= and +Infinity for b > 1. Base 1 is also not rejected when x =3D Infinity: SELECT log('1'::numeric, '12.34'::numeric); -- ERROR: division by zero (correct rejection) SELECT log('1'::numeric, 'Infinity'::numeric); -- Infinity (wrong: the same call with a finite x is rejected) The Infinity special case in the numeric log implementation appears to shortcut the ln(x)/ln(b) computation without considering the sign of ln(b), or the ln(b) =3D 0 case.