isSafeInteger: isSafeIntegralNumber,
} = Number;
+/** Positive zero. */
+export const POSITIVE_ZERO = 0;
+
+/** Negative zero. */
+export const NEGATIVE_ZERO = -0;
+
/**
* Returns the magnitude (absolute value) of the provided value.
*
? n === 0n ? 0n : n < 0n ? -1n : 1n
: isNan(n) || n === 0
? n
- : //deno-lint-ignore no-compare-neg-zero
- n < -0
- ? -1
- : 1;
+ //deno-lint-ignore no-compare-neg-zero
+ : n < -0
+ ? -1
+ : 1;
};
/**
* Returns the result of converting the provided number to an integer
* or infinity.
*
- * ☡ This function does not allow big·int arguments.
+ * ※ This function will never return negative zero.
*/
export const toIntegerOrInfinity = ($) => {
- const integer = trunc($);
+ const integer = trunc(toNumber($));
if (isNan(integer) || integer == 0) {
// The provided value truncs to nan or (positive or negative) zero.
return 0;
}
};
+/**
+ * Returns the result of converting the provided number to an integral
+ * number.
+ *
+ * ※ This function will never return negative zero.
+ */
+export const toIntegralNumber = ($) => {
+ const n = toIntegerOrInfinity($);
+ return !isFiniteNumber(n) || n == 0 ? 0 : n;
+};
+
/**
* Returns the result of converting the provided value to a number.
*