]> Lady’s Gitweb - Pisces/commitdiff
Move numeric constants into value.js
authorLady <redacted>
Tue, 21 Nov 2023 03:04:38 +0000 (22:04 -0500)
committerLady <redacted>
Wed, 22 Nov 2023 02:26:59 +0000 (21:26 -0500)
This follows the pattern of declaring symbol constants here so they are
accessible everywhere.

numeric.js
numeric.test.js
value.js
value.test.js

index f5bc7380a73084007d9d0449727706dacbb35126..9384abcaee946e92869f33250f85ee0cd4c8e98f 100644 (file)
@@ -15,129 +15,13 @@ import {
   substring,
   toString,
 } from "./string.js";
-import { sameValue, toPrimitive } from "./value.js";
-
-export const {
-  /**
-   * ln(10).
-   *
-   * ※ This is an alias for `Math.LN10`.
-   */
-  LN10,
-
-  /**
-   * ln(2).
-   *
-   * ※ This is an alias for `Math.LN2`.
-   */
-  LN2,
-
-  /**
-   * log10(ℇ).
-   *
-   * ※ This is an alias for `Math.LOG10E`.
-   */
-  LOG10E: LOG10ℇ,
-
-  /**
-   * log2(ℇ).
-   *
-   * ※ This is an alias for `Math.LOG2E`.
-   */
-  LOG2E: LOG2ℇ,
-
-  /**
-   * sqrt(½).
-   *
-   * ※ This is an alias for `Math.SQRT1_2`.
-   */
-  SQRT1_2: RECIPROCAL_SQRT2,
-
-  /**
-   * sqrt(2).
-   *
-   * ※ This is an alias for `Math.SQRT2`.
-   */
-  SQRT2,
-
-  /**
-   * The mathematical constant π.
-   *
-   * ※ This is an alias for `Math.PI`.
-   */
-  PI: Π,
-
-  /**
-   * The Euler number.
-   *
-   * ※ This is an alias for `Math.E`.
-   */
-  E: ℇ,
-} = Math;
-
-export const {
-  /**
-   * The largest number value less than infinity.
-   *
-   * ※ This is an alias for `Number.MAX_VALUE`.
-   */
-  MAX_VALUE: MAXIMUM_NUMBER,
-
-  /**
-   * 2**53 - 1.
-   *
-   * ※ This is an alias for `Number.MAX_SAFE_INTEGER`.
-   */
-  MAX_SAFE_INTEGER: MAXIMUM_SAFE_INTEGRAL_NUMBER,
-
-  /**
-   * The smallest number value greater than negative infinity.
-   *
-   * ※ This is an alias for `Number.MIN_VALUE`.
-   */
-  MIN_VALUE: MINIMUM_NUMBER,
-
-  /**
-   * -(2**53 - 1).
-   *
-   * ※ This is an alias for `Number.MIN_SAFE_INTEGER`.
-   */
-  MIN_SAFE_INTEGER: MINIMUM_SAFE_INTEGRAL_NUMBER,
-
-  /**
-   * Negative infinity.
-   *
-   * ※ This is an alias for `Number.NEGATIVE_INFINITY`.
-   */
+import {
+  NAN,
   NEGATIVE_INFINITY,
-
-  /**
-   * Nan.
-   *
-   * ※ This is an alias for `Number.NaN`.
-   */
-  NaN: NAN,
-
-  /**
-   * Positive infinity.
-   *
-   * ※ This is an alias for `Number.POSITIVE_INFINITY`.
-   */
   POSITIVE_INFINITY,
-
-  /**
-   * The difference between 1 and the smallest number greater than 1.
-   *
-   * ※ This is an alias for `Number.EPSILON`.
-   */
-  EPSILON: Ε,
-} = Number;
-
-/** Negative zero. */
-export const NEGATIVE_ZERO = -0;
-
-/** Positive zero. */
-export const POSITIVE_ZERO = 0;
+  sameValue,
+  toPrimitive,
+} from "./value.js";
 
 /**
  * Returns the magnitude (absolute value) of the provided value.
index 9d0dbd1f93ecf4c530640686a57461442190b960..0129ae335b9fff7d777e60b4e9ae2824f957d9dd 100644 (file)
@@ -37,32 +37,17 @@ import {
   isNan,
   isSafeIntegralNumber,
   ln,
-  LN10,
   ln1p,
-  LN2,
   log10,
-  LOG10ℇ,
   log2,
-  LOG2ℇ,
   max,
-  MAXIMUM_NUMBER,
-  MAXIMUM_SAFE_INTEGRAL_NUMBER,
   min,
-  MINIMUM_NUMBER,
-  MINIMUM_SAFE_INTEGRAL_NUMBER,
-  NAN,
-  NEGATIVE_INFINITY,
-  NEGATIVE_ZERO,
-  POSITIVE_INFINITY,
-  POSITIVE_ZERO,
   rand,
-  RECIPROCAL_SQRT2,
   round,
   sgn,
   sin,
   sinh,
   sqrt,
-  SQRT2,
   tan,
   tanh,
   toBigInt,
@@ -76,125 +61,8 @@ import {
   toSignedIntegralNumeric,
   toUnsignedIntegralNumeric,
   trunc,
-  Ε,
-  Π,
-  ℇ,
 } from "./numeric.js";
 
-describe("LN10", () => {
-  it("[[Get]] is ln(10)", () => {
-    assertStrictEquals(LN10, Math.LN10);
-  });
-});
-
-describe("LN2", () => {
-  it("[[Get]] is ln(2)", () => {
-    assertStrictEquals(LN2, Math.LN2);
-  });
-});
-
-describe("LOG10ℇ", () => {
-  it("[[Get]] is log10(ℇ)", () => {
-    assertStrictEquals(LOG10ℇ, Math.LOG10E);
-  });
-});
-
-describe("LOG2ℇ", () => {
-  it("[[Get]] is log2(ℇ)", () => {
-    assertStrictEquals(LOG2ℇ, Math.LOG2E);
-  });
-});
-
-describe("MAXIMUM_NUMBER", () => {
-  it("[[Get]] is the maximum number", () => {
-    assertStrictEquals(MAXIMUM_NUMBER, Number.MAX_VALUE);
-  });
-});
-
-describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
-  it("[[Get]] is the maximum safe integral number", () => {
-    assertStrictEquals(
-      MAXIMUM_SAFE_INTEGRAL_NUMBER,
-      Number.MAX_SAFE_INTEGER,
-    );
-  });
-});
-
-describe("MINIMUM_NUMBER", () => {
-  it("[[Get]] is the minimum number", () => {
-    assertStrictEquals(MINIMUM_NUMBER, Number.MIN_VALUE);
-  });
-});
-
-describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
-  it("[[Get]] is the minimum safe integral number", () => {
-    assertStrictEquals(
-      MINIMUM_SAFE_INTEGRAL_NUMBER,
-      Number.MIN_SAFE_INTEGER,
-    );
-  });
-});
-
-describe("NAN", () => {
-  it("[[Get]] is nan", () => {
-    assertStrictEquals(NAN, NaN);
-  });
-});
-
-describe("NEGATIVE_INFINITY", () => {
-  it("[[Get]] is negative infinity", () => {
-    assertStrictEquals(NEGATIVE_INFINITY, -Infinity);
-  });
-});
-
-describe("NEGATIVE_ZERO", () => {
-  it("[[Get]] is negative zero", () => {
-    assertStrictEquals(NEGATIVE_ZERO, -0);
-  });
-});
-
-describe("POSITIVE_INFINITY", () => {
-  it("[[Get]] is negative infinity", () => {
-    assertStrictEquals(POSITIVE_INFINITY, Infinity);
-  });
-});
-
-describe("POSITIVE_ZERO", () => {
-  it("[[Get]] is positive zero", () => {
-    assertStrictEquals(POSITIVE_ZERO, 0);
-  });
-});
-
-describe("RECIPROCAL_SQRT2", () => {
-  it("[[Get]] is sqrt(½)", () => {
-    assertStrictEquals(RECIPROCAL_SQRT2, Math.SQRT1_2);
-  });
-});
-
-describe("SQRT2", () => {
-  it("[[Get]] is sqrt(2)", () => {
-    assertStrictEquals(SQRT2, Math.SQRT2);
-  });
-});
-
-describe("Ε", () => {
-  it("[[Get]] is ε", () => {
-    assertStrictEquals(Ε, Number.EPSILON);
-  });
-});
-
-describe("Π", () => {
-  it("[[Get]] is π", () => {
-    assertStrictEquals(Π, Math.PI);
-  });
-});
-
-describe("ℇ", () => {
-  it("[[Get]] is ℇ", () => {
-    assertStrictEquals(ℇ, Math.E);
-  });
-});
-
 describe("abs", () => {
   it("[[Call]] returns the absolute value", () => {
     assertStrictEquals(abs(-1), 1);
index d552fdcbbb5ff6349ff751bf4448f8ccbdb721bb..83c1e1803d78d2c35f232faf96bad5aa7a29c931 100644 (file)
--- a/value.js
+++ b/value.js
@@ -45,9 +45,131 @@ export const {
   unscopables: UNSCOPABLES,
 } = Symbol;
 
+export const {
+  /**
+   * ln(10).
+   *
+   * ※ This is an alias for `Math.LN10`.
+   */
+  LN10,
+
+  /**
+   * ln(2).
+   *
+   * ※ This is an alias for `Math.LN2`.
+   */
+  LN2,
+
+  /**
+   * log10(ℇ).
+   *
+   * ※ This is an alias for `Math.LOG10E`.
+   */
+  LOG10E: LOG10ℇ,
+
+  /**
+   * log2(ℇ).
+   *
+   * ※ This is an alias for `Math.LOG2E`.
+   */
+  LOG2E: LOG2ℇ,
+
+  /**
+   * sqrt(½).
+   *
+   * ※ This is an alias for `Math.SQRT1_2`.
+   */
+  SQRT1_2: RECIPROCAL_SQRT2,
+
+  /**
+   * sqrt(2).
+   *
+   * ※ This is an alias for `Math.SQRT2`.
+   */
+  SQRT2,
+
+  /**
+   * The mathematical constant π.
+   *
+   * ※ This is an alias for `Math.PI`.
+   */
+  PI: Π,
+
+  /**
+   * The Euler number.
+   *
+   * ※ This is an alias for `Math.E`.
+   */
+  E: ℇ,
+} = Math;
+
+export const {
+  /**
+   * The largest number value less than infinity.
+   *
+   * ※ This is an alias for `Number.MAX_VALUE`.
+   */
+  MAX_VALUE: MAXIMUM_NUMBER,
+
+  /**
+   * 2**53 - 1.
+   *
+   * ※ This is an alias for `Number.MAX_SAFE_INTEGER`.
+   */
+  MAX_SAFE_INTEGER: MAXIMUM_SAFE_INTEGRAL_NUMBER,
+
+  /**
+   * The smallest number value greater than negative infinity.
+   *
+   * ※ This is an alias for `Number.MIN_VALUE`.
+   */
+  MIN_VALUE: MINIMUM_NUMBER,
+
+  /**
+   * -(2**53 - 1).
+   *
+   * ※ This is an alias for `Number.MIN_SAFE_INTEGER`.
+   */
+  MIN_SAFE_INTEGER: MINIMUM_SAFE_INTEGRAL_NUMBER,
+
+  /**
+   * Negative infinity.
+   *
+   * ※ This is an alias for `Number.NEGATIVE_INFINITY`.
+   */
+  NEGATIVE_INFINITY,
+
+  /**
+   * Nan.
+   *
+   * ※ This is an alias for `Number.NaN`.
+   */
+  NaN: NAN,
+
+  /**
+   * Positive infinity.
+   *
+   * ※ This is an alias for `Number.POSITIVE_INFINITY`.
+   */
+  POSITIVE_INFINITY,
+
+  /**
+   * The difference between 1 and the smallest number greater than 1.
+   *
+   * ※ This is an alias for `Number.EPSILON`.
+   */
+  EPSILON: Ε,
+} = Number;
+
+/** Negative zero. */
+export const NEGATIVE_ZERO = -0;
+
 /** The null primitive. */
 export const NULL = null;
 
+/** Positive zero. */
+export const POSITIVE_ZERO = 0;
+
 /** The undefined primitive. */
 export const UNDEFINED = undefined;
 
@@ -169,10 +291,7 @@ export const {
   toLength,
 } = (() => {
   const { floor, max, min } = Math;
-  const {
-    MAX_SAFE_INTEGER: MAXIMUM_SAFE_INTEGRAL_NUMBER,
-    isNaN: isNan,
-  } = Number;
+  const { isNaN: isNan } = Number;
   const { is } = Object;
   return {
     sameValue: (a, b) => is(a, b),
index 88d727bc50bdb7d4fd2f41b37999f86152ec09ab..7d6a5e13e6e2c3d7c1ffc1c17e6c2abd6a7727a7 100644 (file)
@@ -18,15 +18,30 @@ import {
   HAS_INSTANCE,
   IS_CONCAT_SPREADABLE,
   ITERATOR,
+  LN10,
+  LN2,
+  LOG10ℇ,
+  LOG2ℇ,
   MATCH,
   MATCH_ALL,
+  MAXIMUM_NUMBER,
+  MAXIMUM_SAFE_INTEGRAL_NUMBER,
+  MINIMUM_NUMBER,
+  MINIMUM_SAFE_INTEGRAL_NUMBER,
+  NAN,
+  NEGATIVE_INFINITY,
+  NEGATIVE_ZERO,
   NULL,
   ordinaryToPrimitive,
+  POSITIVE_INFINITY,
+  POSITIVE_ZERO,
+  RECIPROCAL_SQRT2,
   REPLACE,
   sameValue,
   sameValueZero,
   SPECIES,
   SPLIT,
+  SQRT2,
   TO_PRIMITIVE,
   TO_STRING_TAG,
   toIndex,
@@ -35,6 +50,9 @@ import {
   type,
   UNDEFINED,
   UNSCOPABLES,
+  Ε,
+  Π,
+  ℇ,
 } from "./value.js";
 
 describe("ASYNC_ITERATOR", () => {
@@ -64,6 +82,30 @@ describe("ITERATOR", () => {
   });
 });
 
+describe("LN10", () => {
+  it("[[Get]] is ln(10)", () => {
+    assertStrictEquals(LN10, Math.LN10);
+  });
+});
+
+describe("LN2", () => {
+  it("[[Get]] is ln(2)", () => {
+    assertStrictEquals(LN2, Math.LN2);
+  });
+});
+
+describe("LOG10ℇ", () => {
+  it("[[Get]] is log10(ℇ)", () => {
+    assertStrictEquals(LOG10ℇ, Math.LOG10E);
+  });
+});
+
+describe("LOG2ℇ", () => {
+  it("[[Get]] is log2(ℇ)", () => {
+    assertStrictEquals(LOG2ℇ, Math.LOG2E);
+  });
+});
+
 describe("MATCH", () => {
   it("[[Get]] is @@match", () => {
     assertStrictEquals(MATCH, Symbol.match);
@@ -76,12 +118,78 @@ describe("MATCH_ALL", () => {
   });
 });
 
+describe("MAXIMUM_NUMBER", () => {
+  it("[[Get]] is the maximum number", () => {
+    assertStrictEquals(MAXIMUM_NUMBER, Number.MAX_VALUE);
+  });
+});
+
+describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
+  it("[[Get]] is the maximum safe integral number", () => {
+    assertStrictEquals(
+      MAXIMUM_SAFE_INTEGRAL_NUMBER,
+      Number.MAX_SAFE_INTEGER,
+    );
+  });
+});
+
+describe("MINIMUM_NUMBER", () => {
+  it("[[Get]] is the minimum number", () => {
+    assertStrictEquals(MINIMUM_NUMBER, Number.MIN_VALUE);
+  });
+});
+
+describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
+  it("[[Get]] is the minimum safe integral number", () => {
+    assertStrictEquals(
+      MINIMUM_SAFE_INTEGRAL_NUMBER,
+      Number.MIN_SAFE_INTEGER,
+    );
+  });
+});
+
+describe("NAN", () => {
+  it("[[Get]] is nan", () => {
+    assertStrictEquals(NAN, NaN);
+  });
+});
+
+describe("NEGATIVE_INFINITY", () => {
+  it("[[Get]] is negative infinity", () => {
+    assertStrictEquals(NEGATIVE_INFINITY, -Infinity);
+  });
+});
+
+describe("NEGATIVE_ZERO", () => {
+  it("[[Get]] is negative zero", () => {
+    assertStrictEquals(NEGATIVE_ZERO, -0);
+  });
+});
+
 describe("NULL", () => {
   it("[[Get]] is null", () => {
     assertStrictEquals(NULL, null);
   });
 });
 
+describe("POSITIVE_INFINITY", () => {
+  it("[[Get]] is negative infinity", () => {
+    assertStrictEquals(POSITIVE_INFINITY, Infinity);
+  });
+});
+
+describe("POSITIVE_ZERO", () => {
+  it("[[Get]] is positive zero", () => {
+    assertStrictEquals(POSITIVE_ZERO, 0);
+  });
+});
+
+describe("RECIPROCAL_SQRT2", () => {
+  it("[[Get]] is sqrt(½)", () => {
+    assertStrictEquals(RECIPROCAL_SQRT2, Math.SQRT1_2);
+  });
+});
+
 describe("REPLACE", () => {
   it("[[Get]] is @@replace", () => {
     assertStrictEquals(REPLACE, Symbol.replace);
@@ -100,6 +208,12 @@ describe("SPLIT", () => {
   });
 });
 
+describe("SQRT2", () => {
+  it("[[Get]] is sqrt(2)", () => {
+    assertStrictEquals(SQRT2, Math.SQRT2);
+  });
+});
+
 describe("TO_PRIMITIVE", () => {
   it("[[Get]] is @@toPrimitive", () => {
     assertStrictEquals(TO_PRIMITIVE, Symbol.toPrimitive);
@@ -124,6 +238,24 @@ describe("UNSCOPABLES", () => {
   });
 });
 
+describe("Ε", () => {
+  it("[[Get]] is ε", () => {
+    assertStrictEquals(Ε, Number.EPSILON);
+  });
+});
+
+describe("Π", () => {
+  it("[[Get]] is π", () => {
+    assertStrictEquals(Π, Math.PI);
+  });
+});
+
+describe("ℇ", () => {
+  it("[[Get]] is ℇ", () => {
+    assertStrictEquals(ℇ, Math.E);
+  });
+});
+
 describe("ordinaryToPrimitive", () => {
   it("[[Call]] prefers `valueOf` by default", () => {
     const obj = {
This page took 0.115371 seconds and 4 git commands to generate.