On Mon, Feb 26, 2018 at 11:29 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Chapman Flack <chap@anastigmatix.net> writes: > The 0002-*.patch is a proof-of-concept patching float4_numeric and > float8_numeric in the trivial way (just using FLT_DECIMAL_DIG and > DBL_DECIMAL_DIG in place of FLT_DIG and DBL_DIG). It makes the new > regression test pass. (It will only work under a compiler that has > __FLT_DECIMAL_DIG__ and __DBL_DECIMAL_DIG__ available, and I used > those internal versions to avoid mucking with build tooling to change > the target C standard, which I assume wouldn't be welcome anyway.
Nope. TBH, I'd think about just using "DBL_DIG + 3", given our existing coding around extra_float_digits in places like pg_dump and postgres_fdw. The knowledge that you need 2 or 3 extra digits is already well embedded.
but I'm not exactly seeing how that buys us anything.
The bigger question here is whether people actually want this behavioral change. I think there's probably a bigger chance of complaints that "casting 1.1::float8 to numeric now produces some weird, incorrectly-rounded result" than that we make anyone happier.
I have a vague idea that at some point in the past we discussed making this conversion use extra_float_digits, which'd allow satisfying both camps, at the nontrivial price that the conversion would have to be considered stable not immutable. We didn't pull the trigger, if this memory is real at all, presumably because of the mutability issue.
Another idea would be to leave the cast alone and introduce a named function that does the "exact" conversion. Possibly that makes nobody happy, but at least both the cast and the function could be immutable. It'd dodge backwards-compatibility objections, too.
regards, tom lane
Working for a company that
has enterprise customers this can't be overemphasized.
Never require the user to do something so they keep getting the same results.
It doesn't
matter if it's "wrong".
I would vote for a property. If you want the best effort to match the IEEE spec
you need to execute 'set use_ieee_numbers' and you'll get the extra digits and
rounding behavior. If not you'll get the existing behavior.