forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite54a758
committed
Fix corner-case loss of precision in numeric_power().
This fixes a loss of precision that occurs when the first input isvery close to 1, so that its logarithm is very small.Formerly, during the initial low-precision calculation to estimate theresult weight, the logarithm was computed to a local rscale that wascapped to NUMERIC_MAX_DISPLAY_SCALE (1000). However, the base may beas close as 1e-16383 to 1, hence its logarithm may be as small as1e-16383, and so the local rscale needs to be allowed to exceed 16383,otherwise all precision is lost, leading to a poor choice of rscalefor the full-precision calculation.Fix this by removing the cap on the local rscale during the initiallow-precision calculation, as we already do in the full-precisioncalculation. This doesn't change the fact that the initial calculationis a low-precision approximation, computing the logarithm to around 8significant digits, which is very fast, especially when the base isvery close to 1.Patch by me, reviewed by Alvaro Herrera.Discussion:https://postgr.es/m/CAEZATCV-Ceu%2BHpRMf416yUe4KKFv%3DtdgXQAe5-7S9tD%3D5E-T1g%40mail.gmail.com1 parentba216d3 commite54a758
File tree
3 files changed
+12
-1
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+12
-1
lines changedLines changed: 5 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10266 | 10266 |
| |
10267 | 10267 |
| |
10268 | 10268 |
| |
| 10269 | + | |
| 10270 | + | |
| 10271 | + | |
| 10272 | + | |
| 10273 | + | |
10269 | 10274 |
| |
10270 | 10275 |
| |
10271 |
| - | |
10272 | 10276 |
| |
10273 | 10277 |
| |
10274 | 10278 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2483 | 2483 |
| |
2484 | 2484 |
| |
2485 | 2485 |
| |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
2486 | 2492 |
| |
2487 | 2493 |
| |
2488 | 2494 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1148 | 1148 |
| |
1149 | 1149 |
| |
1150 | 1150 |
| |
| 1151 | + | |
1151 | 1152 |
| |
1152 | 1153 |
| |
1153 | 1154 |
| |
|
0 commit comments
Comments
(0)