Skip to content

fix: keep exact negative powers of ten under default precision#430

Open
Solaris-star wants to merge 1 commit into
shopspring:masterfrom
Solaris-star:fix/394-pow-negative-int-precision
Open

fix: keep exact negative powers of ten under default precision#430
Solaris-star wants to merge 1 commit into
shopspring:masterfrom
Solaris-star:fix/394-pow-negative-int-precision

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

Pow / PowInt32 / PowBigInt used DivRound(..., PowPrecisionNegativeExponent) for negative integer exponents. With the default precision of 16, exact values such as 10 ** -17 became 0.

Fix

When the reciprocal rounds to zero, retry DivRound with enough fractional digits for the positive power result (NumDigits), so exact powers of ten stay non-zero without changing rounded results that already fit in the configured precision.

Test plan

  • go test .
  • New regression: TestDecimal_PowNegativeIntegerPowersOfTen for exponents -16/-17/-18/-20 via Pow/PowInt32/PowBigInt

Fixes #394

DivRound with PowPrecisionNegativeExponent (16) collapsed exact values
like 10**-17 to zero. When the reciprocal rounds to zero, retry with
enough digits for the positive power result.

Fixes shopspring#394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pow() Returns Incorrect Result

1 participant