Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMlFN-0002SA-Jl for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Oct 2019 03:54:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMlFL-0001am-7g for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Oct 2019 03:54:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMlFK-0001af-Ss for pgsql-bugs@lists.postgresql.org; Tue, 22 Oct 2019 03:54:11 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iMlFD-0001Xl-Oa for pgsql-bugs@lists.postgresql.org; Tue, 22 Oct 2019 03:54:09 +0000 Received: from [192.168.127.1] (port=52575 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iMlF9-000G9O-Nh; Tue, 22 Oct 2019 03:53:59 +0000 Received: from localhost ([127.0.0.1]:43672 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iMlF9-0004Z0-JI; Tue, 22 Oct 2019 03:53:59 +0000 From: Andrew Gierth To: Tom Lane Cc: Gilleain Torrance , "pgsql-bugs\@lists.postgresql.org" Subject: Re: Incorrect rounding of double values at max precision In-Reply-To: <26443.1571712071@sss.pgh.pa.us> (Tom Lane's message of "Mon, 21 Oct 2019 22:41:11 -0400") Message-ID: <871rv5h3dc.fsf@news-spur.riddles.org.uk> References: <5045.1571686957@sss.pgh.pa.us> <875zkhhjs0.fsf@news-spur.riddles.org.uk> <26443.1571712071@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Tue, 22 Oct 2019 04:53:59 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: >> Perhaps it would make more sense for the float8 to numeric cast to >> look at the requested typmod and use that for the conversion? Tom> As things stand right now, float8_numeric has no idea what the Tom> target typmod is; any typmod-driven rounding happens in a separate Tom> function call afterwards. I don't recall whether the parser's Tom> casting infrastructure could support merging those steps, As far as I can tell it does; it looks at whether the cast function takes a typmod parameter, and if it does, it passes the typmod, otherwise it generates a separate typmod coercion and stacks that on top of the cast proper. So changing the function declaration to include a typmod parameter, and using it, should just work... but I've not tested it yet. Tom> and I'm not sure it matters in most cases. Commonly, we don't have Tom> a target typmod. (Still, if we do, having two separate rounding Tom> steps isn't nice.) So we'd still need to decide what to do in the no-typmod case. -- Andrew (irc:RhodiumToad)