forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7d9a473
committed
Improve type numeric's calculations for ln(), log(), exp(), pow().
Set the "rscales" for intermediate-result calculations to ensure thatsuitable numbers of significant digits are maintained throughout. Theprevious coding hadn't thought this through in any detail, and as a resultcould deliver results with many inaccurate digits, or in the worst caseseven fail with divide-by-zero errors as a result of losing all nonzerodigits of intermediate results.In exp_var(), get rid entirely of the logic that separated the calculationinto integer and fractional parts: that was neither accurate norparticularly fast. The existing range-reduction method of dividing by 2^ncan be applied across the full input range instead of only 0..1, as long aswe are careful to set an appropriate rscale for each step.Also fix the logic in mul_var() for shortening the calculation when thecaller asks for fewer output digits than an exact calculation wouldrequire. This bug doesn't affect simple multiplications since that codepath asks for an exact result, but it does contribute to accuracy issuesin the transcendental math functions.In passing, improve performance of mul_var() a bit by forcing the shorterinput to be on the left, thus reducing the number of iterations of theouter loop and probably also reducing the number of carry-propagationsteps needed.This is arguably a bug fix, but in view of the lack of field complaints,it does not seem worth the risk of back-patching.Dean Rasheed1 parente57646e commit7d9a473
File tree
5 files changed
+2853
-227
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
5 files changed
+2853
-227
lines changed0 commit comments
Comments
(0)