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 1r5VZh-00Dlie-A9 for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Nov 2023 18:34:17 +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 1r5VZf-001YTI-Rk for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Nov 2023 18:34:15 +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 1r5VZf-001YTA-Iy for pgsql-bugs@lists.postgresql.org; Tue, 21 Nov 2023 18:34:15 +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 1r5VZd-007e4h-Fe for pgsql-bugs@lists.postgresql.org; Tue, 21 Nov 2023 18:34:15 +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 3ALIYACm1526794; Tue, 21 Nov 2023 13:34:10 -0500 From: Tom Lane To: Gallacher Neil cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: ERROR: value out of range: underflow in numeric log calculation In-reply-to: References: Comments: In-reply-to Gallacher Neil message dated "Tue, 21 Nov 2023 13:26:16 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1526792.1700591650.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 21 Nov 2023 13:34:10 -0500 Message-ID: <1526793.1700591650@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Gallacher Neil writes: > When executing log calculations (example below): > SELECT 1.0 * exp(-1.0 *(ln(2) * (1695993520/86400.0)) / 0.04) AS result_= test; > The following error occurs. > ERROR: value out of range: underflow Yup. > I can however understand that an individual might wish to know that the = result of a calculation cannot be represented by the system due to its sma= ll value however I don't believe it should be the default behaviour. You'd be in a minority on that opinion. In this case you could work around it by asking for the calculation to be done in numeric rather than float8: regression=3D# SELECT 1.0 * exp(-1.0 *(ln(2::numeric) * (1695993520/86400.= 0)) / 0.04) AS result_test; = = = = = = result_test = = = = = = = = --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------------------------------------------------------------------------= ------------------------------------------- 0.00000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000 (1 row) but I'm not sure how far that covers your real use-case. regards, tom lane