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)));
+ }
+ }
},
};
})();