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 1sQbV6-00AeBy-BA for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jul 2024 23:41:00 +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 1sQbV4-00GLnD-7j for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jul 2024 23:40:58 +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 1sQbV3-00GLn5-FL for pgsql-hackers@lists.postgresql.org; Sun, 07 Jul 2024 23:40:57 +0000 Received: from fout1-smtp.messagingengine.com ([103.168.172.144]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQbV0-000x1l-Qw for pgsql-hackers@postgresql.org; Sun, 07 Jul 2024 23:40:56 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 1573813805D6; Sun, 7 Jul 2024 19:40:53 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Sun, 07 Jul 2024 19:40:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1720395653; x=1720482053; bh=81VJaSE4Yo sGmyjkZ4Y4bBBXXUUEXaOKlaGVIjbEllk=; b=qfoiDdTBotIL/bLpH1pQZv2IZG ofEtXjU3tUgbIcKT8v3BBCCqm1Yh/5xgSqQB8412++OZNbsUh1tcswuMBjOdYc8I z3wmffr7VQFnbiLX/2/qkyFnCh7N/AXZwpcGNFu7lR6wSc0dKi3HQxklx4cCBM+M tXH6EtCtnwrw0nn8w/bIVbQtTCFhRnJCD5+WMUBUsjAAhRCTKEo8+/QqfutIpFB4 V29AQowta3/E0N+t6ASBPg09CbMJvo4Mzx/1qzTU+gj+U5WKUUlwo5tL98TGJIzF i63cm4mnBSzfMM6iZKQojekLmV9DgKu0AzXJRD/hJZXwy1ZGkpwB6jdQ+M2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1720395653; x=1720482053; bh=81VJaSE4YosGmyjkZ4Y4bBBXXUUE XaOKlaGVIjbEllk=; b=PGVNUJt7Vvb88/qcB++1YLi40xSMZgZx4I8OYuOWm1z3 yChhGqg3dXakXGFvKxnuUWl9TWjNO2bvZKWWskFuJ4svAmJguEI+Ebhbm7s8/uS9 qyxJp7odSUxu/N2esyreOErO1FjQC5A97yYmQBcVXWuQriUwzYGHtMuu7nRxu9KF TGVFcTWljLQKZGkFEHd7oGpoaySXJiyR3btgRZdn3WSLa188DlQ/+HZRS0fFcIwd ejV/qUPsAiWuz3Kufw/bO+52UwFZdJlcu42+jVNuQBqzkmtXmiN6P/KLJBygHk0/ JvBjMk+0nAcwZSwnJStXa8v7Kt3VfE5u1TL01hzzNg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeigddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedflfhovghl ucflrggtohgsshhonhdfuceojhhovghlsegtohhmphhilhgvrhdrohhrgheqnecuggftrf grthhtvghrnhepkeehhedufffhvdeuhfeihfdvjeejueduhffgudehgeevieetkeevvdej vedvudelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epjhhovghlsegtohhmphhilhgvrhdrohhrgh X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7F2A331A0065; Sun, 7 Jul 2024 19:40:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb MIME-Version: 1.0 Message-Id: In-Reply-To: References: Date: Mon, 08 Jul 2024 01:40:31 +0200 From: "Joel Jacobson" To: "Dean Rasheed" , pgsql-hackers Subject: Re: Incorrect results from numeric round() and trunc() Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Jul 7, 2024, at 13:28, Dean Rasheed wrote: > I've also tidied up a bit by replacing all instances of SHRT_MAX with > a new constant NUMERIC_WEIGHT_MAX, whose name more accurately > describes the limit, as used in various other overflow checks. Having thought a bit more on this, I think we probably need a DEC_DIGITS sensitive definition of NUMERIC_WEIGHT_MAX, since per spec the max range for numeric is 0x20000 (131072) decimal digits. Therefore, I think perhaps what we want is: +#define NUMERIC_DSCALE_MIN 0 +#define NUMERIC_WEIGHT_MAX ((0x20000/DEC_DIGITS)-1) +#define NUMERIC_WEIGHT_MIN (-(NUMERIC_DSCALE_MAX+1)/DEC_DIGITS) Maybe also 0x20000 (131072) should be a defined constant. Regards, Joel