postgresql/src/backend/utils
Tom Lane d761fe2182 Fix precision and rounding issues in money multiplication and division.
The cash_div_intX functions applied rint() to the result of the division.
That's not merely useless (because the result is already an integer) but
it causes precision loss for values larger than 2^52 or so, because of
the forced conversion to float8.

On the other hand, the cash_mul_fltX functions neglected to apply rint() to
their multiplication results, thus possibly causing off-by-one outputs.

Per C standard, arithmetic between any integral value and a float value is
performed in float format.  Thus, cash_mul_flt4 and cash_div_flt4 produced
answers good to only about six digits, even when the float value is exact.
We can improve matters noticeably by widening the float inputs to double.
(It's tempting to consider using "long double" arithmetic if available,
but that's probably too much of a stretch for a back-patched fix.)

Also, document that cash_div_intX operators truncate rather than round.

Per bug #14663 from Richard Pistole.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/22403.1495223615@sss.pgh.pa.us
2017-05-21 13:05:16 -04:00
..
adt Fix precision and rounding issues in money multiplication and division. 2017-05-21 13:05:16 -04:00
cache Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
error Fix new warnings from GCC 7 2017-04-17 13:59:46 -04:00
fmgr Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
hash Adjust outdated comment. 2017-04-25 10:58:45 -04:00
init Show more processes in pg_stat_activity. 2017-03-26 22:02:22 -04:00
mb Post-PG 10 beta1 pgperltidy run 2017-05-17 19:01:23 -04:00
misc Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
mmgr Make slab allocator work on platforms with MAXIMUM_ALIGNOF < sizeof(int). 2017-05-18 22:22:13 +03:00
resowner Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
sort Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
time Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
.gitignore Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
errcodes.txt Identity columns 2017-04-06 08:41:37 -04:00
Gen_dummy_probes.pl Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
Gen_dummy_probes.sed Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
Gen_fmgrtab.pl Post-PG 10 beta1 pgperltidy run 2017-05-17 19:01:23 -04:00
generate-errcodes.pl Clean up Perl code according to perlcritic 2017-03-27 08:18:22 -04:00
Makefile Fix parallel make issue with new fmgrprotos.h 2017-01-23 15:36:27 -05:00
probes.d Rename dtrace probes for ongoing xlog -> wal conversion. 2017-02-09 16:40:19 -05:00