-
Bug
-
Resolution: Fixed
-
P2
-
8
-
None
-
b93
-
Verified
From Andre Bargull on the nashorn-dev list
The implementation for Math.round() does not match what's specified in the ES spec.
A few test cases which currently fail:
assertEq(-Infinity, 1/Math.round(-0.5))
assertEq(9007199254740991, Math.round(9007199254740991))
assertEq(18446744073709552000, Math.round(9223372036854775807*2))
The NativeMath#round() method should be changed as follows:
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object round(final Object self, final Object x) {
double d = JSType.toNumber(x);
int e = Math.getExponent(d);
if (e >= 52) {
return d;
}
return Math.copySign(Math.floor(d + 0.5), d);
}
- André
The implementation for Math.round() does not match what's specified in the ES spec.
A few test cases which currently fail:
assertEq(-Infinity, 1/Math.round(-0.5))
assertEq(9007199254740991, Math.round(9007199254740991))
assertEq(18446744073709552000, Math.round(9223372036854775807*2))
The NativeMath#round() method should be changed as follows:
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object round(final Object self, final Object x) {
double d = JSType.toNumber(x);
int e = Math.getExponent(d);
if (e >= 52) {
return d;
}
return Math.copySign(Math.floor(d + 0.5), d);
}
- André