diff -r 05224402145d -r 4ff4e27465e0 emul/mini/src/main/java/java/lang/Math.java --- a/emul/mini/src/main/java/java/lang/Math.java Wed Jan 23 20:39:23 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/Math.java Mon Jan 28 16:26:52 2013 +0100 @@ -375,6 +375,68 @@ public static double floor(double a) { throw new UnsupportedOperationException(); } + /** + * Computes the remainder operation on two arguments as prescribed + * by the IEEE 754 standard. + * The remainder value is mathematically equal to + * f1 - f2 × n, + * where n is the mathematical integer closest to the exact + * mathematical value of the quotient {@code f1/f2}, and if two + * mathematical integers are equally close to {@code f1/f2}, + * then n is the integer that is even. If the remainder is + * zero, its sign is the same as the sign of the first argument. + * Special cases: + * + * + * @param f1 the dividend. + * @param f2 the divisor. + * @return the remainder when {@code f1} is divided by + * {@code f2}. + */ +// public static double IEEEremainder(double f1, double f2) { +// return f1 % f2; +// } + + /** + * Returns the {@code double} value that is closest in value + * to the argument and is equal to a mathematical integer. If two + * {@code double} values that are mathematical integers are + * equally close, the result is the integer value that is + * even. Special cases: + * + * + * @param a a {@code double} value. + * @return the closest floating-point value to {@code a} that is + * equal to a mathematical integer. + */ + public static double rint(double a) { + double ceil = ceil(a); + double floor = floor(a); + + double dc = ceil - a; + double df = a - floor; + + if (dc < df) { + return ceil; + } else if (dc > df) { + return floor; + } + + int tenC = (int) (ceil % 10.0); + + if (tenC % 2 == 0) { + return ceil; + } else { + return floor; + } + } /** * Returns the angle theta from the conversion of rectangular