]> Lady’s Gitweb - Pisces/commitdiff
Rename to{I∣Ui}ntN to to{S∣Uns}ignedIntegralNumeric
authorLady <redacted>
Sun, 25 Jun 2023 05:19:23 +0000 (22:19 -0700)
committerLady <redacted>
Sun, 25 Jun 2023 05:23:24 +0000 (22:23 -0700)
“int·N” and “u·int·N” are not really ♓🌟 Piscēs terms.

numeric.js
numeric.test.js

index 4a066f77098eca61d57a908cc75bf3eddd1112b5..02ca876477a7a01f7dc1bfb6c1e542a0a92eeaf6 100644 (file)
@@ -1,7 +1,7 @@
 // ♓🌟 Piscēs ∷ numeric.js
 // ====================================================================
 //
-// Copyright © 2022 Lady [@ Lady’s Computer].
+// Copyright © 2022–2023 Lady [@ Lady’s Computer].
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -444,7 +444,9 @@ export const {
     clz32: ($) => {
       const n = toNumeric($);
       return clz32(
-        typeof n === "bigint" ? toNumber(toUintN(32, n)) : n,
+        typeof n === "bigint"
+          ? toNumber(toUnsignedIntegralNumeric(32, n))
+          : n,
       );
     },
     toFloat32: ($) => fround(toNumber($)),
@@ -679,68 +681,6 @@ export const {
   };
 })();
 
-export const {
-  /**
-   * Returns the result of converting the provided value to fit within
-   * the provided number of bits as a signed integer.
-   *
-   * ※ Unlike BigInt.asIntN, this function accepts both big·int and
-   * number values.
-   *
-   * ☡ The first argument, the number of bits, must be a number.
-   */
-  toIntN,
-
-  /**
-   * Returns the result of converting the provided value to fit within
-   * the provided number of bits as an unsigned integer.
-   *
-   * ※ Unlike BigInt.asUintN, this function accepts both big·int and
-   * number values.
-   *
-   * ☡ The first argument, the number of bits, must be a number.
-   */
-  toUintN,
-} = (() => {
-  const { asIntN, asUintN } = BigInt;
-  return {
-    toIntN: (n, $) => {
-      const prim = toPrimitive($);
-      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($);
-      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)));
-        }
-      }
-    },
-  };
-})();
-
 /**
  * Returns the result of converting the provided number to an integral
  * number.
@@ -803,3 +743,65 @@ export const toNumeric = ($) => {
   const primValue = toPrimitive($, "number");
   return typeof primValue === "bigint" ? primValue : +primValue;
 };
+
+export const {
+  /**
+   * Returns the result of converting the provided value to fit within
+   * the provided number of bits as a signed integer.
+   *
+   * ※ Unlike BigInt.asIntN, this function accepts both big·int and
+   * number values.
+   *
+   * ☡ The first argument, the number of bits, must be a number.
+   */
+  toSignedIntegralNumeric,
+
+  /**
+   * Returns the result of converting the provided value to fit within
+   * the provided number of bits as an unsigned integer.
+   *
+   * ※ Unlike BigInt.asUintN, this function accepts both big·int and
+   * number values.
+   *
+   * ☡ The first argument, the number of bits, must be a number.
+   */
+  toUnsignedIntegralNumeric,
+} = (() => {
+  const { asIntN, asUintN } = BigInt;
+  return {
+    toSignedIntegralNumeric: (n, $) => {
+      const prim = toPrimitive($);
+      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)));
+        }
+      }
+    },
+    toUnsignedIntegralNumeric: (n, $) => {
+      const prim = toPrimitive($);
+      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)));
+        }
+      }
+    },
+  };
+})();
index 27776cde54c4daef8aaa8f27d9356e7d954f88cb..4d3d2cb8616cdccacd4594935e80ba8c82e5469b 100644 (file)
@@ -1,7 +1,7 @@
 // ♓🌟 Piscēs ∷ numeric.test.js
 // ====================================================================
 //
-// Copyright © 2022 Lady [@ Lady’s Computer].
+// Copyright © 2022–2023 Lady [@ Lady’s Computer].
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -28,10 +28,10 @@ import {
   toFloat32,
   toIntegralNumber,
   toIntegralNumberOrInfinity,
-  toIntN,
   toNumber,
   toNumeric,
-  toUintN,
+  toSignedIntegralNumeric,
+  toUnsignedIntegralNumeric,
 } from "./numeric.js";
 
 describe("NEGATIVE_ZERO", () => {
@@ -206,18 +206,18 @@ describe("toFloat32", () => {
   });
 });
 
-describe("toIntN", () => {
+describe("toSignedIntegralNumeric", () => {
   it("[[Call]] converts to an int·n", () => {
-    assertStrictEquals(toIntN(2, 7n), -1n);
+    assertStrictEquals(toSignedIntegralNumeric(2, 7n), -1n);
   });
 
   it("[[Call]] works with numbers", () => {
-    assertStrictEquals(toIntN(2, 7), -1);
+    assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
   });
 
   it("[[Call]] works with non‐integers", () => {
-    assertStrictEquals(toIntN(2, 7.21), -1);
-    assertStrictEquals(toIntN(2, Infinity), 0);
+    assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
+    assertStrictEquals(toSignedIntegralNumeric(2, Infinity), 0);
   });
 });
 
@@ -306,17 +306,17 @@ describe("toNumeric", () => {
   });
 });
 
-describe("toUintN", () => {
+describe("toUnsignedIntegralNumeric", () => {
   it("[[Call]] converts to an int·n", () => {
-    assertStrictEquals(toUintN(2, 7n), 3n);
+    assertStrictEquals(toUnsignedIntegralNumeric(2, 7n), 3n);
   });
 
   it("[[Call]] works with numbers", () => {
-    assertStrictEquals(toUintN(2, 7), 3);
+    assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
   });
 
   it("[[Call]] works with non‐integers", () => {
-    assertStrictEquals(toUintN(2, 7.21), 3);
-    assertStrictEquals(toUintN(2, Infinity), 0);
+    assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
+    assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity), 0);
   });
 });
This page took 0.156676 seconds and 4 git commands to generate.