]> Lady’s Gitweb - Pisces/blobdiff - numeric.js
Add methods for own entries and values to object.js
[Pisces] / numeric.js
index 9384abcaee946e92869f33250f85ee0cd4c8e98f..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,
@@ -21,6 +22,7 @@ import {
   POSITIVE_INFINITY,
   sameValue,
   toPrimitive,
+  UNDEFINED,
 } from "./value.js";
 
 /**
@@ -318,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.
@@ -342,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 {
@@ -353,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
@@ -367,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.
@@ -403,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).
@@ -551,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.030953 seconds and 4 git commands to generate.