1.1 --- a/emul/mini/src/main/java/java/lang/Math.java Wed Jan 23 20:39:23 2013 +0100
1.2 +++ b/emul/mini/src/main/java/java/lang/Math.java Mon Jan 28 16:26:52 2013 +0100
1.3 @@ -375,6 +375,68 @@
1.4 public static double floor(double a) {
1.5 throw new UnsupportedOperationException();
1.6 }
1.7 + /**
1.8 + * Computes the remainder operation on two arguments as prescribed
1.9 + * by the IEEE 754 standard.
1.10 + * The remainder value is mathematically equal to
1.11 + * <code>f1 - f2</code> × <i>n</i>,
1.12 + * where <i>n</i> is the mathematical integer closest to the exact
1.13 + * mathematical value of the quotient {@code f1/f2}, and if two
1.14 + * mathematical integers are equally close to {@code f1/f2},
1.15 + * then <i>n</i> is the integer that is even. If the remainder is
1.16 + * zero, its sign is the same as the sign of the first argument.
1.17 + * Special cases:
1.18 + * <ul><li>If either argument is NaN, or the first argument is infinite,
1.19 + * or the second argument is positive zero or negative zero, then the
1.20 + * result is NaN.
1.21 + * <li>If the first argument is finite and the second argument is
1.22 + * infinite, then the result is the same as the first argument.</ul>
1.23 + *
1.24 + * @param f1 the dividend.
1.25 + * @param f2 the divisor.
1.26 + * @return the remainder when {@code f1} is divided by
1.27 + * {@code f2}.
1.28 + */
1.29 +// public static double IEEEremainder(double f1, double f2) {
1.30 +// return f1 % f2;
1.31 +// }
1.32 +
1.33 + /**
1.34 + * Returns the {@code double} value that is closest in value
1.35 + * to the argument and is equal to a mathematical integer. If two
1.36 + * {@code double} values that are mathematical integers are
1.37 + * equally close, the result is the integer value that is
1.38 + * even. Special cases:
1.39 + * <ul><li>If the argument value is already equal to a mathematical
1.40 + * integer, then the result is the same as the argument.
1.41 + * <li>If the argument is NaN or an infinity or positive zero or negative
1.42 + * zero, then the result is the same as the argument.</ul>
1.43 + *
1.44 + * @param a a {@code double} value.
1.45 + * @return the closest floating-point value to {@code a} that is
1.46 + * equal to a mathematical integer.
1.47 + */
1.48 + public static double rint(double a) {
1.49 + double ceil = ceil(a);
1.50 + double floor = floor(a);
1.51 +
1.52 + double dc = ceil - a;
1.53 + double df = a - floor;
1.54 +
1.55 + if (dc < df) {
1.56 + return ceil;
1.57 + } else if (dc > df) {
1.58 + return floor;
1.59 + }
1.60 +
1.61 + int tenC = (int) (ceil % 10.0);
1.62 +
1.63 + if (tenC % 2 == 0) {
1.64 + return ceil;
1.65 + } else {
1.66 + return floor;
1.67 + }
1.68 + }
1.69
1.70 /**
1.71 * Returns the angle <i>theta</i> from the conversion of rectangular