]> Lady’s Gitweb - Pisces/blobdiff - numeric.js
Add methods for own entries and values to object.js
[Pisces] / numeric.js
index f5bc7380a73084007d9d0449727706dacbb35126..079e56e0c36c64f9c10abaf655d57b93033553c0 100644 (file)
@@ -8,6 +8,7 @@
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import { call, createArrowFunction } from "./function.js";
+import { defineOwnDataProperty } from "./object.js";
 import {
   stringCatenate,
   stringPadEnd,
@@ -15,129 +16,14 @@ 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,
+  UNDEFINED,
+} from "./value.js";
 
 /**
  * Returns the magnitude (absolute value) of the provided value.
@@ -434,11 +320,11 @@ export const log2 = createArrowFunction(Math.log2);
  * big·int.
  */
 export const max = Object.defineProperties((...$s) => {
-  let highest = undefined;
+  let highest = UNDEFINED;
   for (let i = 0; i < $s.length; ++i) {
     // Iterate over all the numbers.
     const number = toNumeric($s[i]);
-    if (highest === undefined) {
+    if (highest === UNDEFINED) {
       // The current number is the first one.
       if (isNan(number)) {
         // The current number is nan.
@@ -458,7 +344,7 @@ export const max = Object.defineProperties((...$s) => {
       } else if (sameValue(number, 0) && sameValue(highest, -0)) {
         // The current number is +0 and the highest number is -0.
         highest = 0;
-      } else if (highest === undefined || number > highest) {
+      } else if (number > highest) {
         // The current number is greater than the highest number.
         highest = number;
       } else {
@@ -469,7 +355,10 @@ export const max = Object.defineProperties((...$s) => {
     }
   }
   return highest ?? NEGATIVE_INFINITY;
-}, { name: { value: "max" }, length: { value: 2 } });
+}, {
+  name: defineOwnDataProperty(Object.create(null), "value", "max"),
+  length: defineOwnDataProperty(Object.create(null), "value", 2),
+});
 
 /**
  * Returns the lowest value of the provided arguments, or positive
@@ -483,11 +372,11 @@ export const max = Object.defineProperties((...$s) => {
  * big·int.
  */
 export const min = Object.defineProperties((...$s) => {
-  let lowest = undefined;
+  let lowest = UNDEFINED;
   for (let i = 0; i < $s.length; ++i) {
     // Iterate over all the numbers.
     const number = toNumeric($s[i]);
-    if (lowest === undefined) {
+    if (lowest === UNDEFINED) {
       // The current number is the first one.
       if (isNan(number)) {
         // The current number is nan.
@@ -519,7 +408,10 @@ export const min = Object.defineProperties((...$s) => {
     }
   }
   return lowest ?? POSITIVE_INFINITY;
-}, { name: { value: "min" }, length: { value: 2 } });
+}, {
+  name: defineOwnDataProperty(Object.create(null), "value", "min"),
+  length: defineOwnDataProperty(Object.create(null), "value", 2),
+});
 
 /**
  * Returns a pseudo·random value in the range [0, 1).
@@ -667,12 +559,12 @@ export const {
           return call(
             numberToExponential,
             n,
-            [fractionDigits === undefined ? fractionDigits : f],
+            [fractionDigits === UNDEFINED ? fractionDigits : f],
           );
         } else {
           const digits = call(bigintToString, n, [10]);
           const { length } = digits;
-          if (fractionDigits === undefined) {
+          if (fractionDigits === UNDEFINED) {
             return length === 1
               ? `${digits[0]}e+0`
               : `${digits[0]}.${substring(digits, 1)}e+${length - 1}`;
This page took 0.028282 seconds and 4 git commands to generate.