Re: Incorrect rounding of double values at max precision

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Gilleain Torrance <Gilleain(dot)Torrance(at)alfasystems(dot)com>, "pgsql-bugs\(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Incorrect rounding of double values at max precision
Date: 2019-10-22 03:53:59
Message-ID: 871rv5h3dc.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 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)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Maciek Sakrejda 2019-10-22 05:29:32 Re: Duplicate Workers entries in some EXPLAIN plans
Previous Message Tom Lane 2019-10-22 02:41:11 Re: Incorrect rounding of double values at max precision