fix(log): respect config for bigint logs; handle 0n (fixes #3539)#3571
fix(log): respect config for bigint logs; handle 0n (fixes #3539)#3571philpeng1 wants to merge 1 commit intojosdejong:developfrom
Conversation
|
Thanks so much for your interest in mathjs and for your efforts! Apologies, but there is already a PR (from the project owner) for part of #3539: see #3555. You can either close this one, or mark it WIP, and we can revisit the other aspects after #3555 lands. But be aware that towards the end of the (lengthy!) discussion for #3374, we decided that the |
|
Thanks for the explanation! Bit of a blunder from my part, didn't read everything through. I'll mark this as Closed for now.. Thanks for maintaining this project! |
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.