Skip to content

Commit ce98a1f

Browse files
committed
Fix Math.sumPrecise to correctly return -0 for empty arrays
- Empty arrays should always return -0 per spec - Separate logic for empty vs all-zeros cases - Matches behavior of Hermes implementation
1 parent 0b1f690 commit ce98a1f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/NativeMath.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,12 @@ private static Object sumPrecise(
781781

782782
// Handle all zeros (including empty input)
783783
if (allZeros) {
784-
// Empty input or all zeros - return -0 for empty, appropriate zero for actual zeros
785-
return ScriptRuntime.wrapNumber(partialsSize == 0 || hasNegativeZero ? -0.0 : 0.0);
784+
// Empty input should always return -0
785+
if (partialsSize == 0) {
786+
return ScriptRuntime.wrapNumber(-0.0);
787+
}
788+
// All zeros - return -0 if any negative zeros, otherwise +0
789+
return ScriptRuntime.wrapNumber(hasNegativeZero ? -0.0 : 0.0);
786790
}
787791

788792
// Sum partials

0 commit comments

Comments
 (0)