From: Lady Date: Sat, 25 Nov 2023 18:34:26 +0000 (-0500) Subject: Minor refactors to numeric.js X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/393a3cfeae0f2156bbae4d37db16d96cf2b55de6?ds=inline Minor refactors to numeric.js --- diff --git a/numeric.js b/numeric.js index 9384abc..079e56e 100644 --- a/numeric.js +++ b/numeric.js @@ -8,6 +8,7 @@ // file, You can obtain one at . 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}`;