Skip to content

Commit 444523b

Browse files
dynstwebmaster128
authored andcommitted
self-documenting code
Number(bigint) will clamp large numbers to positive or negative Infinity so the code works fine but this is simply clearer-looking.
1 parent 721a41c commit 444523b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/math/src/decimal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class Decimal {
9191

9292
public static compare(a: Decimal, b: Decimal): number {
9393
if (a.fractionalDigits !== b.fractionalDigits) throw new Error("Fractional digits do not match");
94-
return Math.sign(Number(a.data.atomics - b.data.atomics));
94+
const difference = a.data.atomics - b.data.atomics;
95+
if (difference < 0n) return -1;
96+
if (difference > 0n) return 1;
97+
return 0;
9598
}
9699

97100
public get atomics(): string {

0 commit comments

Comments
 (0)