fix: round zeta BigNumber digit count to avoid non-integer factorial#3683
Open
xianjianlf2 wants to merge 1 commit into
Open
fix: round zeta BigNumber digit count to avoid non-integer factorial#3683xianjianlf2 wants to merge 1 commit into
xianjianlf2 wants to merge 1 commit into
Conversation
The BigNumber branch of zeta derived its digit count from Math.abs(Math.log10(config.relTol)). When relTol is not an exact power of ten (e.g. 5e-8, or 1e-320 where floating point rounding makes log10 non-integer), this produced a non-integer digit count that eventually reached factorial/gamma as a non-integer BigNumber, throwing "Integer BigNumber expected". Round the value so the digit count is always an integer. Closes josdejong#3532
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The BigNumber branch of
zetaderived its digit count fromMath.abs(Math.log10(config.relTol)). WhenrelTolis not an exact power of ten (e.g.5e-8, or1e-320where floating-point rounding makeslog10non-integer), this produced a non-integer digit count. That value eventually reachedfactorial/gammaas a non-integer BigNumber, throwingInteger BigNumber expected.Fix
Round the derived value with
Math.round(...)so the digit count is always an integer, regardless of floating-point noise inMath.log10.Testing
Added a unit test in
test/unit-tests/function/special/zeta.test.jsthat configures BigNumber mode with arelTolwhose base-10 logarithm is non-integer (5e-16) and asserts thatzeta(3)no longer throws and returns the expected value.Closes #3532