X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/8fcb8f6d937fadd7aa8016f8ba33004d1bd79bf0..2aaa51c0d16852726d2402bfb7953fab182afc01:/numeric.js diff --git a/numeric.js b/numeric.js index 44c7cd5..1d0a543 100644 --- a/numeric.js +++ b/numeric.js @@ -605,15 +605,37 @@ export const { return { toIntN: (n, $) => { const prim = toPrimitive($); - const big·int = toBigInt(prim); - const intN = asIntN(n, big·int); - return typeof prim === "bigint" ? intN : toNumber(intN); + if (typeof prim === "bigint") { + // The primitive value is a big·int. + return asIntN(n, prim); + } else { + // The primitive value is not a big·int. + const int = trunc(prim); + if (!isFiniteNumber(int) || int == 0) { + // The truncated value is zero or not finite. + return 0; + } else { + // The truncated value is finite. + return toNumber(asIntN(n, toBigInt(int))); + } + } }, toUintN: (n, $) => { const prim = toPrimitive($); - const big·int = toBigInt(prim); - const uintN = asUintN(n, big·int); - return typeof prim === "bigint" ? uintN : toNumber(uintN); + if (typeof prim === "bigint") { + // The primitive value is a big·int. + return asUintN(n, prim); + } else { + // The primitive value is not a big·int. + const int = trunc(prim); + if (!isFiniteNumber(int) || int == 0) { + // The truncated value is zero or not finite. + return 0; + } else { + // The truncated value is finite. + return toNumber(asUintN(n, toBigInt(int))); + } + } }, }; })();