src/share/classes/java/lang/StrictMath.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 799,810 **** */ public static long max(long a, long b) { return (a >= b) ? a : b; } ! private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f); ! private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d); /** * Returns the greater of two {@code float} values. That is, * the result is the argument closer to positive infinity. If the * arguments have the same value, the result is that same --- 799,811 ---- */ public static long max(long a, long b) { return (a >= b) ? a : b; } ! // Use raw bit-wise conversions on guaranteed non-NaN arguments. ! private static long negativeZeroFloatBits = Float.floatToRawIntBits(-0.0f); ! private static long negativeZeroDoubleBits = Double.doubleToRawLongBits(-0.0d); /** * Returns the greater of two {@code float} values. That is, * the result is the argument closer to positive infinity. If the * arguments have the same value, the result is that same
*** 817,829 **** * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static float max(float a, float b) { ! if (a != a) return a; // a is NaN ! if ((a == 0.0f) && (b == 0.0f) ! && (Float.floatToIntBits(a) == negativeZeroFloatBits)) { return b; } return (a >= b) ? a : b; } --- 818,833 ---- * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static float max(float a, float b) { ! if (a != a) ! return a; // a is NaN ! if ((a == 0.0f) && ! (b == 0.0f) && ! (Float.floatToRawIntBits(a) == negativeZeroFloatBits)) { ! // Raw conversion ok since NaN can't map to -0.0. return b; } return (a >= b) ? a : b; }
*** 840,852 **** * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static double max(double a, double b) { ! if (a != a) return a; // a is NaN ! if ((a == 0.0d) && (b == 0.0d) ! && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) { return b; } return (a >= b) ? a : b; } --- 844,859 ---- * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static double max(double a, double b) { ! if (a != a) ! return a; // a is NaN ! if ((a == 0.0d) && ! (b == 0.0d) && ! (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) { ! // Raw conversion ok since NaN can't map to -0.0. return b; } return (a >= b) ? a : b; }
*** 891,903 **** * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b.} */ public static float min(float a, float b) { ! if (a != a) return a; // a is NaN ! if ((a == 0.0f) && (b == 0.0f) ! && (Float.floatToIntBits(b) == negativeZeroFloatBits)) { return b; } return (a <= b) ? a : b; } --- 898,913 ---- * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b.} */ public static float min(float a, float b) { ! if (a != a) ! return a; // a is NaN ! if ((a == 0.0f) && ! (b == 0.0f) && ! (Float.floatToRawIntBits(b) == negativeZeroFloatBits)) { ! // Raw conversion ok since NaN can't map to -0.0. return b; } return (a <= b) ? a : b; }
*** 914,926 **** * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b}. */ public static double min(double a, double b) { ! if (a != a) return a; // a is NaN ! if ((a == 0.0d) && (b == 0.0d) ! && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) { return b; } return (a <= b) ? a : b; } --- 924,939 ---- * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b}. */ public static double min(double a, double b) { ! if (a != a) ! return a; // a is NaN ! if ((a == 0.0d) && ! (b == 0.0d) && ! (Double.doubleToRawLongBits(b) == negativeZeroDoubleBits)) { ! // Raw conversion ok since NaN can't map to -0.0. return b; } return (a <= b) ? a : b; }