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 1sQlIU-00BTHo-4d for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 10:08:38 +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 1sQlIR-004QJC-IG for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 10:08:35 +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.94.2) (envelope-from ) id 1sQlIR-004QJ4-3O for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2024 10:08:35 +0000 Received: from fhigh4-smtp.messagingengine.com ([103.168.172.155]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQlIO-0010X2-J2 for pgsql-hackers@postgresql.org; Mon, 08 Jul 2024 10:08:33 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E1C0D114041C; Mon, 8 Jul 2024 06:08:31 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Mon, 08 Jul 2024 06:08:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc: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=1720433311; x=1720519711; bh=vmxIlfS1L5 T5WFV6PkSp4j3PBdVrR5rsjajC8HvEhMc=; b=mfeCW2sf+hLIQu1uwfK/WYhOHj aOFqQKknWd0tb840+/mfCgxh9otzKNPsV44iBpQPgKS1pIj21pW2HHdqXSliPtv+ Ok78RuZwqCKIg2/BlWR1MLVFriiYeubtF18+IUhvbbn/dzEvRxat3mx2T85bSujO uk+oA4gHDJzE1sVugE34yXnJEgXoymasUBUOO02wMp0pTCkek06zQgGnEzePJztu BFHZdLSBxjrBVyOeS9MlQF3ctOJp2fXt3+KaIUo4MZH2x4ML7aRUjJkqLzafWK2N MpGs8CyL+jF413sBhor93xG++5hXY1qAEBfqsd3EJuOVVF2f744jd4YcPYpA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1720433311; x=1720519711; bh=vmxIlfS1L5T5WFV6PkSp4j3PBdVr R5rsjajC8HvEhMc=; b=hk3EaQ5uRrXwy/NOCzt8pCWl3btJ+0f26i6eoIhpxlZV Zt2W/sKHW+awU3NC+36WhaxsuwYEQpAXEikJwVrC1ZvRP/OVrIkacHBRE44YTg6/ LjyLJ/a2C2D3/y0TWEfc2EXtkz8Pi40X/NDA0vxt6FyRUwL8RCbUxMVxvXceBy0k hCO3bRhm0lIwluGwbutNcC2ODlXIA1DGxxqOuInBA46Fi0yHayUqxxfydA5m/oft U6wXh91hbSpUGDVNuEw8Vpu7nICJenvp3z7I1TSe4MQ9fwxACPhFuyihkf+DsTbB bctMbbsyVU/5ju17QXkZNvhyQ58GZNl+rjC/iSOxnQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdflohgv lhculfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtf frrghtthgvrhhnpefhfedugeffvddtteeluefhffekledtudekhfekkeeileelfffhfedt ffejgfejfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjohgvlhestghomhhpihhlvghrrdhorhhg X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7030731A0066; Mon, 8 Jul 2024 06:08:30 -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 12:08:10 +0200 From: "Joel Jacobson" To: "Dean Rasheed" Cc: 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 Mon, Jul 8, 2024, at 11:45, Dean Rasheed wrote: > On Mon, 8 Jul 2024 at 00:40, Joel Jacobson wrote: >> >> 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. >> > > No, the maximum weight is determined by the use of int16 to store the > weight. Therefore if you did reduce DEC_DIGITS to 1 or 2, the number > of decimal digits allowed before the decimal point would be reduced > too. OK, that can actually be seen as a feature, especially since it's of course more likely DEC_DIGITS could increase in the future than decrease. For example, let's say we would double it to 8, then if NUMERIC_WEIGHT_MAX would still be 0x7FFF (32767), then the maximum range for numeric would increase from 131072 to 262144 decimal digits allowed before the decimal point. LGTM. Regards, Joel