-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle bigints properly in more cases (#3345)
* fix: Handle bigints properly in more cases * Allow a bigint to appear in a max/min of nonhomogeneous arguments * If randomInt is called with a bigint or a pair of bigints, return a bigint. * Preserve uniformity of results if randomInt is called with a very large range. * Extend log, log2, and log10 to bigints * Add tests for all of the above issues. * Bonus: fix one JSDoc comment issue. If every PR fixes one, we will soon get through the 150+ * fix: Refactors per comments and 1 bonus doc test (isInteger) * chore: fix lint --------- Co-authored-by: Jos de Jong <[email protected]>
- Loading branch information
Showing
20 changed files
with
224 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Build a bigint logarithm function from a number logarithm, | ||
* still returning a number. The idea is that 15 hexadecimal digits | ||
* (60 bits) saturates the mantissa of the log, and each additional hex | ||
* digit effectively just adds the log of 16 to the resulting value. So | ||
* convert the most significant 15 hex digits to a number and take its | ||
* log, and then add the log of 16 for each additional hex digit that | ||
* was in the bigint. | ||
* For negative numbers (complex logarithms), following the bignum | ||
* implementation, it just downgrades to number and uses the complex result. | ||
* @param {number} log16 the log of 16 | ||
* @param {(number) -> number} numberLog the logarithm function for numbers | ||
* @param {ConfigurationObject} config the mathjs configuration | ||
* @param {(number) -> Complex} cplx the associated Complex log | ||
* @returns {(bigint) -> number} the corresponding logarithm for bigints | ||
*/ | ||
export function promoteLogarithm (log16, numberLog, config, cplx) { | ||
return function (b) { | ||
if (b > 0 || config.predictable) { | ||
if (b <= 0) return NaN | ||
const s = b.toString(16) | ||
const s15 = s.substring(0, 15) | ||
return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15)) | ||
} | ||
return cplx(b.toNumber()) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.