fix(log): respect config for bigint logs; handle 0n (fixes #3539) #3571
+114
−11
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.
Fixes #3539
Summary:
Details
When number: 'bigint' and numberFallback: 'BigNumber', convert bigint inputs to BigNumber and use:
log: x.ln()
log10: x.log()
log2: x.log(2)
Otherwise, use the bigint promotion helper for number results.
In the bigint promotion helper:
Return numberLog(0) for 0n.
For negatives: NaN when predictable: true, else compute complex via number downgrade.
Avoid calling non-existent BigInt methods.
Tests:
Added regression tests:
log(123n) returns BigNumber.
log10(10n) -> BigNumber(1), log2(1024n) -> BigNumber(10).
floor(log10(1n)) -> BigNumber(0) (no round error).
Negative bigint: predictable true -> NaN; predictable false -> Complex.
log2(2n70n) -> 70, log10(10n16n) -> 16.