This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Decimal128 } from "../src/decimal128.mjs"; | ||
|
||
const MAX_SIGNIFICANT_DIGITS = 34; | ||
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS); | ||
|
||
const zero = new Decimal128("0"); | ||
const minusZero = new Decimal128("-0"); | ||
const one = new Decimal128("1"); | ||
const minusOne = new Decimal128("-1"); | ||
const two = new Decimal128("2"); | ||
|
||
describe("neg", () => { | ||
test("minus zero", () => { | ||
expect(new Decimal128("-0").neg().toString()).toStrictEqual("0"); | ||
}); | ||
test("zero", () => { | ||
expect(new Decimal128("0").neg().toString()).toStrictEqual("-0"); | ||
}); | ||
test("NaN", () => { | ||
expect(new Decimal128("NaN").neg().toString()).toStrictEqual("NaN"); | ||
}); | ||
test("negative number", () => { | ||
expect(new Decimal128("-42.51").neg().toString()).toStrictEqual( | ||
"42.51" | ||
); | ||
}); | ||
test("positive number", () => { | ||
expect(new Decimal128("42.51").neg().toString()).toStrictEqual( | ||
"-42.51" | ||
); | ||
}); | ||
test("preserve trailing zeros", () => { | ||
expect( | ||
new Decimal128("-42.510").neg().toString({ normalize: false }) | ||
).toStrictEqual("42.510"); | ||
}); | ||
test("-Infinity", () => { | ||
expect(new Decimal128("-Infinity").neg().toString()).toStrictEqual( | ||
"Infinity" | ||
); | ||
}); | ||
test("Infinity", () => { | ||
expect(new Decimal128("Infinity").neg().toString()).toStrictEqual( | ||
"-Infinity" | ||
); | ||
}); | ||
test("limit of digits", () => { | ||
expect(new Decimal128("-" + bigDigits).neg().toString()).toStrictEqual( | ||
bigDigits | ||
); | ||
}); | ||
}); |