From: Lady Date: Sun, 18 Sep 2022 22:02:31 +0000 (-0700) Subject: Add POSITIVE_ZERO and NEGATIVE_ZERO to numeric.js X-Git-Tag: 0.2.0~1 X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/f3e417be2077db5839dcada4aa1395ae2e9337ba Add POSITIVE_ZERO and NEGATIVE_ZERO to numeric.js --- diff --git a/numeric.js b/numeric.js index 1d0a543..ce92585 100644 --- a/numeric.js +++ b/numeric.js @@ -377,6 +377,12 @@ export const { 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. * @@ -560,10 +566,10 @@ export const sgn = ($) => { ? 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; }; /** diff --git a/numeric.test.js b/numeric.test.js index 96f51c1..6c58d04 100644 --- a/numeric.test.js +++ b/numeric.test.js @@ -19,6 +19,8 @@ import { clz32, max, min, + NEGATIVE_ZERO, + POSITIVE_ZERO, sgn, toBigInt, toFloat32, @@ -29,6 +31,18 @@ import { toUintN, } from "./numeric.js"; +describe("NEGATIVE_ZERO", () => { + it("[[Get]] is negative zero", () => { + assertStrictEquals(NEGATIVE_ZERO, -0); + }); +}); + +describe("POSITIVE_ZERO", () => { + it("[[Get]] is positive zero", () => { + assertStrictEquals(POSITIVE_ZERO, 0); + }); +}); + describe("abs", () => { it("[[Call]] returns the absolute value", () => { assertStrictEquals(abs(-1), 1);