// 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,
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.
* 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.
} 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 {
}
}
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
* 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.
}
}
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).
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}`;