From: Lady Date: Tue, 21 Nov 2023 03:04:38 +0000 (-0500) Subject: Move numeric constants into value.js X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/70b032d26faece9d6573e6f0b2375f071bbcc866 Move numeric constants into value.js This follows the pattern of declaring symbol constants here so they are accessible everywhere. --- diff --git a/numeric.js b/numeric.js index f5bc738..9384abc 100644 --- a/numeric.js +++ b/numeric.js @@ -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. diff --git a/numeric.test.js b/numeric.test.js index 9d0dbd1..0129ae3 100644 --- a/numeric.test.js +++ b/numeric.test.js @@ -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); diff --git a/value.js b/value.js index d552fdc..83c1e18 100644 --- 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), diff --git a/value.test.js b/value.test.js index 88d727b..7d6a5e1 100644 --- a/value.test.js +++ b/value.test.js @@ -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 = {