Skip to content

Commit 2c8b319

Browse files
committed
Small optimization in rounding
Instead of doing a multiplication here, we can just check if the remainder is zero. This matters a bit more for TimeDuration and RoundNumberToIncrementAsIfPositive, because we avoid a BigInt multiplication. UPSTREAM_COMMIT=407adc9e221eecb97e4db1c7b2b8e2b41cbea29a
1 parent 5830124 commit 2c8b319

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/timeduration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class TimeDuration {
132132
const r2 = JSBI.add(r1, increment);
133133
const cmp = compare(abs(JSBI.multiply(remainder, TWO)), increment);
134134
const unsignedRoundingMode = GetUnsignedRoundingMode(mode, sign);
135-
const rounded = JSBI.equal(abs(this.totalNs), r1)
135+
const rounded = JSBI.equal(remainder, ZERO)
136136
? r1
137137
: ApplyUnsignedRoundingMode(r1, r2, cmp, isEven(quotient), unsignedRoundingMode);
138138
const result = sign === 'positive' ? rounded : JSBI.unaryMinus(rounded);

0 commit comments

Comments
 (0)