Description
nextAfter(double, double) is added in StrictMath 1.6, so one needs to test with Java 1.6 to see thi.
There are various boundary errors with nextAfter(double, double) - see below.
I think these are partially due to missing checks for special cases (e.g. the NaNs), and partially due to the following code:
if (d * (direction - d) >= 0) { // we should increase the mantissa
This appears to be a shorthand for something like:
if (((d >=0) && (direction >= d)) || ((d<0) && (direction <0))) { // we should increase the mantissa
however the expression (direction - d) overlows for some double values, thus causing the wrong branch to be taken.
double nextAfter(-0.0, -0.0) expected -0.0 actual 4.9E-324 entries [1, 1]
double nextAfter(-0.0, 0.0) expected 0.0 actual 4.9E-324 entries [1, 2]
double nextAfter(-0.0, NaN) expected NaN actual 4.9E-324 entries [1, 3]
double nextAfter(0.0, -0.0) expected -0.0 actual 4.9E-324 entries [2, 1]
double nextAfter(0.0, 0.0) expected 0.0 actual 4.9E-324 entries [2, 2]
double nextAfter(0.0, NaN) expected NaN actual 4.9E-324 entries [2, 3]
double nextAfter(-Infinity, NaN) expected NaN actual -Infinity entries [4, 3]
double nextAfter(Infinity, NaN) expected NaN actual Infinity entries [5, 3]
double nextAfter(-1.7976931348623157E308, NaN) expected NaN actual -1.7976931348623155E308 entries [6, 3]
double nextAfter(1.7976931348623157E308, NaN) expected NaN actual 1.7976931348623155E308 entries [7, 3]
double nextAfter(-1.1102230246251565E-16, NaN) expected NaN actual -1.1102230246251564E-16 entries [8, 3]
double nextAfter(1.1102230246251565E-16, NaN) expected NaN actual 1.1102230246251564E-16 entries [9, 3]
double nextAfter(-2.2250738585072014E-308, -0.0) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 1]
double nextAfter(-2.2250738585072014E-308, 0.0) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 2]
double nextAfter(-2.2250738585072014E-308, NaN) expected NaN actual -2.225073858507201E-308 entries [10, 3]
double nextAfter(-2.2250738585072014E-308, 1.1102230246251565E-16) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 9]
double nextAfter(-2.2250738585072014E-308, 2.2250738585072014E-308) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 11]
double nextAfter(-2.2250738585072014E-308, -4.9E-324) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 12]
double nextAfter(-2.2250738585072014E-308, 4.9E-324) expected -2.225073858507201E-308 actual -2.225073858507202E-308 entries [10, 13]
double nextAfter(2.2250738585072014E-308, -0.0) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 1]
double nextAfter(2.2250738585072014E-308, 0.0) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 2]
double nextAfter(2.2250738585072014E-308, NaN) expected NaN actual 2.225073858507201E-308 entries [11, 3]
double nextAfter(2.2250738585072014E-308, -1.1102230246251565E-16) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 8]
double nextAfter(2.2250738585072014E-308, -2.2250738585072014E-308) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 10]
double nextAfter(2.2250738585072014E-308, -4.9E-324) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 12]
double nextAfter(2.2250738585072014E-308, 4.9E-324) expected 2.225073858507201E-308 actual 2.225073858507202E-308 entries [11, 13]
double nextAfter(-4.9E-324, -0.0) expected -0.0 actual -1.0E-323 entries [12, 1]
double nextAfter(-4.9E-324, 0.0) expected -0.0 actual -1.0E-323 entries [12, 2]
double nextAfter(-4.9E-324, NaN) expected NaN actual -0.0 entries [12, 3]
double nextAfter(-4.9E-324, 1.1102230246251565E-16) expected -0.0 actual -1.0E-323 entries [12, 9]
double nextAfter(-4.9E-324, 2.2250738585072014E-308) expected -0.0 actual -1.0E-323 entries [12, 11]
double nextAfter(-4.9E-324, 4.9E-324) expected -0.0 actual -1.0E-323 entries [12, 13]
double nextAfter(4.9E-324, -0.0) expected 0.0 actual 1.0E-323 entries [13, 1]
double nextAfter(4.9E-324, 0.0) expected 0.0 actual 1.0E-323 entries [13, 2]
double nextAfter(4.9E-324, NaN) expected NaN actual 0.0 entries [13, 3]
double nextAfter(4.9E-324, -1.1102230246251565E-16) expected 0.0 actual 1.0E-323 entries [13, 8]
double nextAfter(4.9E-324, -2.2250738585072014E-308) expected 0.0 actual 1.0E-323 entries [13, 10]
double nextAfter(4.9E-324, -4.9E-324) expected 0.0 actual 1.0E-323 entries [13, 12]
Attachments
Issue Links
- is related to
-
MATH-478 FastMath is not an exact replacement for StrictMath
- Closed