]> Lady’s Gitweb - Pisces/blobdiff - numeric.test.js
Make base32 handling less forgiving
[Pisces] / numeric.test.js
index 23dbd892af8fff7ad01ea4c4c6bde141188e0155..27776cde54c4daef8aaa8f27d9356e7d954f88cb 100644 (file)
@@ -23,6 +23,8 @@ import {
   POSITIVE_ZERO,
   sgn,
   toBigInt,
   POSITIVE_ZERO,
   sgn,
   toBigInt,
+  toExponentialNotation,
+  toFixedDecimalNotation,
   toFloat32,
   toIntegralNumber,
   toIntegralNumberOrInfinity,
   toFloat32,
   toIntegralNumber,
   toIntegralNumberOrInfinity,
@@ -141,6 +143,53 @@ describe("toBigInt", () => {
   });
 });
 
   });
 });
 
+describe("toExponentialNotation", () => {
+  it("[[Call]] converts to exponential notation", () => {
+    assertStrictEquals(toExponentialNotation(231), "2.31e+2");
+  });
+
+  it("[[Call]] works with big·ints", () => {
+    assertStrictEquals(
+      toExponentialNotation(9007199254740993n),
+      "9.007199254740993e+15",
+    );
+  });
+
+  it("[[Call]] respects the specified number of fractional digits", () => {
+    assertStrictEquals(
+      toExponentialNotation(.00000000642, 3),
+      "6.420e-9",
+    );
+    assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
+    assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
+    assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
+    assertStrictEquals(
+      toExponentialNotation(6420000000n, 3),
+      "6.420e+9",
+    );
+    assertStrictEquals(toExponentialNotation(6910n, 1), "6.9e+3");
+    assertStrictEquals(toExponentialNotation(6850n, 1), "6.9e+3");
+    assertStrictEquals(toExponentialNotation(4199n, 2), "4.20e+3");
+  });
+});
+
+describe("toFixedDecimalNotation", () => {
+  it("[[Call]] converts to fixed decimal notation", () => {
+    assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
+  });
+
+  it("[[Call]] works with big·ints", () => {
+    assertStrictEquals(
+      toFixedDecimalNotation(9007199254740993n),
+      "9007199254740993",
+    );
+    assertStrictEquals(
+      toFixedDecimalNotation(9007199254740993n, 2),
+      "9007199254740993.00",
+    );
+  });
+});
+
 describe("toFloat32", () => {
   it("[[Call]] returns the 32‐bit floating‐point representation", () => {
     assertStrictEquals(
 describe("toFloat32", () => {
   it("[[Call]] returns the 32‐bit floating‐point representation", () => {
     assertStrictEquals(
This page took 0.022579 seconds and 4 git commands to generate.