1.1 --- a/rt/emul/mini/src/main/java/java/lang/Double.java Fri Mar 08 23:43:01 2013 +0100
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Double.java Sat Mar 09 11:58:50 2013 +0100
1.3 @@ -809,15 +809,17 @@
1.4 * @return the bits that represent the floating-point number.
1.5 */
1.6 public static long doubleToLongBits(double value) {
1.7 - throw new UnsupportedOperationException();
1.8 -// long result = doubleToRawLongBits(value);
1.9 -// // Check for NaN based on values of bit fields, maximum
1.10 -// // exponent and nonzero significand.
1.11 -// if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
1.12 -// DoubleConsts.EXP_BIT_MASK) &&
1.13 -// (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
1.14 -// result = 0x7ff8000000000000L;
1.15 -// return result;
1.16 + final long EXP_BIT_MASK = 9218868437227405312L;
1.17 + final long SIGNIF_BIT_MASK = 4503599627370495L;
1.18 +
1.19 + long result = doubleToRawLongBits(value);
1.20 + // Check for NaN based on values of bit fields, maximum
1.21 + // exponent and nonzero significand.
1.22 + if ( ((result & EXP_BIT_MASK) ==
1.23 + EXP_BIT_MASK) &&
1.24 + (result & SIGNIF_BIT_MASK) != 0L)
1.25 + result = 0x7ff8000000000000L;
1.26 + return result;
1.27 }
1.28
1.29 /**
1.30 @@ -856,7 +858,21 @@
1.31 * @return the bits that represent the floating-point number.
1.32 * @since 1.3
1.33 */
1.34 - public static native long doubleToRawLongBits(double value);
1.35 + public static long doubleToRawLongBits(double value) {
1.36 + int[] arr = { 0, 0 };
1.37 + doubleToRawLongBits(value, arr);
1.38 + long l = arr[1];
1.39 + return (l << 32) | arr[0];
1.40 + }
1.41 +
1.42 + @JavaScriptBody(args = { "value", "arr" }, body = ""
1.43 + + "var a = new ArrayBuffer(8);"
1.44 + + "new Float64Array(a)[0] = value;"
1.45 + + "var out = new Int32Array(a);"
1.46 + + "arr[0] = out[0];"
1.47 + + "arr[1] = out[1];"
1.48 + )
1.49 + private static native void doubleToRawLongBits(double value, int[] arr);
1.50
1.51 /**
1.52 * Returns the {@code double} value corresponding to a given