]> Lady’s Gitweb - Pisces/commitdiff
Add POSITIVE_ZERO and NEGATIVE_ZERO to numeric.js
authorLady <redacted>
Sun, 18 Sep 2022 22:02:31 +0000 (15:02 -0700)
committerLady <redacted>
Fri, 12 May 2023 03:56:48 +0000 (20:56 -0700)
numeric.js
numeric.test.js

index 1d0a5435bb75512cd18b657759fdc6fccff85c89..ce92585a4a887b7c66f2af33a5cc344615ddf422 100644 (file)
@@ -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;
 };
 
 /**
index 96f51c1614e8cde3d1f7302d7e860ec1b278376d..6c58d04d7971187b2ca04d5fbabfb97aa29bb92b 100644 (file)
@@ -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);
This page took 0.059012 seconds and 4 git commands to generate.