Skip to content

Commit 07298e8

Browse files
committed
Fix -0 and argument type in ApplyUnsignedRoundingMode
Narrow the argument type of cmp to -1 | 0 | 1. The multiplication at one of the call sites may additionally result in -0, so add +0 to neutralize that.
1 parent 0e71ed3 commit 07298e8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/ecmascript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4611,7 +4611,8 @@ export function RoundNumberToIncrementAsIfPositive(
46114611
}
46124612
// Similar to the comparison in RoundNumberToIncrement, but multiplied by an
46134613
// extra sign to make sure we treat it as positive
4614-
const cmp = compare(abs(JSBI.multiply(remainder, TWO)), increment) * (JSBI.lessThan(quantity, ZERO) ? -1 : 1);
4614+
const cmp = (compare(abs(JSBI.multiply(remainder, TWO)), increment) * (JSBI.lessThan(quantity, ZERO) ? -1 : 1) +
4615+
0) as -1 | 0 | 1;
46154616
const rounded = JSBI.equal(remainder, ZERO)
46164617
? quotient
46174618
: ApplyUnsignedRoundingMode(r1, r2, cmp, isEven(r1), unsignedRoundingMode);

lib/math.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function GetUnsignedRoundingMode(
8282
export function ApplyUnsignedRoundingMode<T extends number | JSBI>(
8383
r1: T,
8484
r2: T,
85-
cmp: number,
85+
cmp: -1 | 0 | 1,
8686
evenCardinality: boolean,
8787
unsignedRoundingMode: UnsignedRoundingMode
8888
) {

0 commit comments

Comments
 (0)