postgresql/src
Tom Lane 5032f704ee 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:17 -04:00
..
backend Fix precision and rounding issues in money multiplication and division. 2017-05-21 13:05:17 -04:00
bin Make psql handle EOF during COPY FROM STDIN properly on all platforms. 2017-05-17 12:24:19 -04:00
common pgindent run for 9.5 2015-05-23 21:35:49 -04:00
include Fix race condition leading to hanging logical slot creation. 2017-05-13 14:21:00 -07:00
interfaces Stamp 9.5.7. 2017-05-08 17:17:18 -04:00
makefiles Link $(WIN32RES) into single-file modules only when PGFILEDESC is set. 2015-08-05 20:45:21 -04:00
pl Translation updates 2017-05-08 10:13:00 -04:00
port Stamp 9.5.7. 2017-05-08 17:17:18 -04:00
template AIX: Test the -qlonglong option before use. 2015-07-17 03:01:29 -04:00
test Fix precision and rounding issues in money multiplication and division. 2017-05-21 13:05:17 -04:00
timezone Fix new warnings from GCC 7 2017-05-16 08:43:55 -04:00
tools Honor PROVE_FLAGS environment setting 2017-05-12 11:26:40 -04:00
tutorial Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Install TAP test infrastructure so it's available for extension testing. 2016-09-23 15:50:00 -04:00
Makefile.global.in Honor PROVE_FLAGS environment setting 2017-05-12 11:26:40 -04:00
Makefile.shlib Fix typos in comments. 2017-02-06 11:34:18 +02:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00