forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd761fe2
committed
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) butit causes precision loss for values larger than 2^52 or so, because ofthe forced conversion to float8.On the other hand, the cash_mul_fltX functions neglected to apply rint() totheir multiplication results, thus possibly causing off-by-one outputs.Per C standard, arithmetic between any integral value and a float value isperformed in float format. Thus, cash_mul_flt4 and cash_div_flt4 producedanswers 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.us1 parent2dd510e commitd761fe2
File tree
4 files changed
+75
-8
lines changed- doc/src/sgml
- src
- backend/utils/adt
- test/regress
- expected
- sql
4 files changed
+75
-8
lines changedLines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
983 | 983 |
| |
984 | 984 |
| |
985 | 985 |
| |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
986 | 991 |
| |
987 | 992 |
| |
988 | 993 |
| |
|
Lines changed: 8 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
667 | 667 |
| |
668 | 668 |
| |
669 | 669 |
| |
670 |
| - | |
| 670 | + | |
671 | 671 |
| |
672 | 672 |
| |
673 | 673 |
| |
| |||
682 | 682 |
| |
683 | 683 |
| |
684 | 684 |
| |
685 |
| - | |
| 685 | + | |
686 | 686 |
| |
687 | 687 |
| |
688 | 688 |
| |
| |||
717 | 717 |
| |
718 | 718 |
| |
719 | 719 |
| |
720 |
| - | |
| 720 | + | |
721 | 721 |
| |
722 | 722 |
| |
723 | 723 |
| |
| |||
732 | 732 |
| |
733 | 733 |
| |
734 | 734 |
| |
735 |
| - | |
| 735 | + | |
736 | 736 |
| |
737 | 737 |
| |
738 | 738 |
| |
| |||
753 | 753 |
| |
754 | 754 |
| |
755 | 755 |
| |
756 |
| - | |
| 756 | + | |
757 | 757 |
| |
758 | 758 |
| |
759 | 759 |
| |
| |||
802 | 802 |
| |
803 | 803 |
| |
804 | 804 |
| |
805 |
| - | |
| 805 | + | |
806 | 806 |
| |
807 | 807 |
| |
808 | 808 |
| |
| |||
854 | 854 |
| |
855 | 855 |
| |
856 | 856 |
| |
857 |
| - | |
| 857 | + | |
858 | 858 |
| |
859 | 859 |
| |
860 | 860 |
| |
| |||
904 | 904 |
| |
905 | 905 |
| |
906 | 906 |
| |
907 |
| - | |
| 907 | + | |
908 | 908 |
| |
909 | 909 |
| |
910 | 910 |
| |
|
Lines changed: 50 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
359 | 359 |
| |
360 | 360 |
| |
361 | 361 |
| |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
362 | 412 |
| |
363 | 413 |
| |
364 | 414 |
| |
|
Lines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
97 | 97 |
| |
98 | 98 |
| |
99 | 99 |
| |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
100 | 112 |
| |
101 | 113 |
| |
102 | 114 |
| |
|
0 commit comments
Comments
(0)