forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit18a02ad
committed
Fix corner-case loss of precision in numeric pow() calculation
Commit7d9a473 greatly improved theaccuracy of the numeric transcendental functions, however it failed toconsider the case where the result from pow() is close to the overflowthreshold, for example 0.12 ^ -2345.6. For such inputs, where theresult has more than 2000 digits before the decimal point, the decimalresult weight estimate was being clamped to 2000, leading to a loss ofprecision in the final calculation.Fix this by replacing the clamping code with an overflow test thataborts the calculation early if the final result is sure to overflow,based on the overflow limit in exp_var(). This provides the sameprotection against integer overflow in the subsequent result scalecomputation as the original clamping code, but it also ensures thatprecision is never lost and saves compute cycles in cases that aresure to overflow.The new early overflow test works with the initial low-precisionresult (expected to be accurate to around 8 significant digits) andincludes a small fuzz factor to ensure that it doesn't kick in forvalues that would not overflow exp_var(), so the overall overflowthreshold of pow() is unchanged and consistent for all inputs withnon-integer exponents.Author: Dean RasheedReviewed-by: Tom LaneDiscussion:http://www.postgresql.org/message-id/CAEZATCUj3U-cQj0jjoia=qgs0SjE3auroxh8swvNKvZWUqegrg@mail.gmail.comSee-also:http://www.postgresql.org/message-id/CAEZATCV7w+8iB=07dJ8Q0zihXQT1semcQuTeK+4_rogC_zq5Hw@mail.gmail.com1 parentc1543a8 commit18a02ad
File tree
3 files changed
+40
-4
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+40
-4
lines changedLines changed: 16 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7591 | 7591 |
| |
7592 | 7592 |
| |
7593 | 7593 |
| |
| 7594 | + | |
7594 | 7595 |
| |
7595 | 7596 |
| |
7596 | 7597 |
| |
| |||
7992 | 7993 |
| |
7993 | 7994 |
| |
7994 | 7995 |
| |
| 7996 | + | |
| 7997 | + | |
| 7998 | + | |
| 7999 | + | |
| 8000 | + | |
| 8001 | + | |
| 8002 | + | |
| 8003 | + | |
| 8004 | + | |
7995 | 8005 |
| |
7996 | 8006 |
| |
7997 | 8007 |
| |
| |||
8006 | 8016 |
| |
8007 | 8017 |
| |
8008 | 8018 |
| |
8009 |
| - | |
| 8019 | + | |
| 8020 | + | |
| 8021 | + | |
| 8022 | + | |
| 8023 | + | |
8010 | 8024 |
| |
8011 |
| - | |
8012 |
| - | |
8013 |
| - | |
| 8025 | + | |
8014 | 8026 |
| |
8015 | 8027 |
| |
8016 | 8028 |
| |
|
0 commit comments
Comments
(0)