Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ private static double round(double x) {
if (isNaN(x) || isInfinite(x)) {
return x;
}
return DoubleMath.roundToLong(x, RoundingMode.HALF_EVEN);
return DoubleMath.roundToLong(x, RoundingMode.HALF_UP);
}

private static Number sign(Number x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,13 @@ public void floor_invalidArgs_throwsException(String expr) {
@TestParameters("{expr: 'math.round(-1.5)' , expectedResult: -2.0}")
@TestParameters("{expr: 'math.round(-1.2)' , expectedResult: -1.0}")
@TestParameters("{expr: 'math.round(-1.6)' , expectedResult: -2.0}")
// Discriminating tie cases: confirm "ties round away from zero" (HALF_UP), not
// banker's rounding (HALF_EVEN). 1.5/-1.5 above don't distingish the two because
// their nearest-even neighbor (2/-2) is also the away-from-zero neighbor.
@TestParameters("{expr: 'math.round(0.5)' , expectedResult: 1.0}")
@TestParameters("{expr: 'math.round(2.5)' , expectedResult: 3.0}")
@TestParameters("{expr: 'math.round(-0.5)' , expectedResult: -1.0}")
@TestParameters("{expr: 'math.round(-2.5)' , expectedResult: -3.0}")
@TestParameters("{expr: 'math.round(0.0/0.0)' , expectedResult: NaN}")
@TestParameters("{expr: 'math.round(1.0/0.0)' , expectedResult: Infinity}")
@TestParameters("{expr: 'math.round(-1.0/0.0)' , expectedResult: -Infinity}")
Expand Down
Loading