909 * {@code f2}; and a value greater than {@code 0}
910 * if {@code f1} is numerically greater than
911 * {@code f2}.
912 * @since 1.4
913 */
914 public static int compare(float f1, float f2) {
915 if (f1 < f2)
916 return -1; // Neither val is NaN, thisVal is smaller
917 if (f1 > f2)
918 return 1; // Neither val is NaN, thisVal is larger
919
920 // Cannot use floatToRawIntBits because of possibility of NaNs.
921 int thisBits = Float.floatToIntBits(f1);
922 int anotherBits = Float.floatToIntBits(f2);
923
924 return (thisBits == anotherBits ? 0 : // Values are equal
925 (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
926 1)); // (0.0, -0.0) or (NaN, !NaN)
927 }
928
929 /** use serialVersionUID from JDK 1.0.2 for interoperability */
930 private static final long serialVersionUID = -2671257302660747028L;
931 }
|
909 * {@code f2}; and a value greater than {@code 0}
910 * if {@code f1} is numerically greater than
911 * {@code f2}.
912 * @since 1.4
913 */
914 public static int compare(float f1, float f2) {
915 if (f1 < f2)
916 return -1; // Neither val is NaN, thisVal is smaller
917 if (f1 > f2)
918 return 1; // Neither val is NaN, thisVal is larger
919
920 // Cannot use floatToRawIntBits because of possibility of NaNs.
921 int thisBits = Float.floatToIntBits(f1);
922 int anotherBits = Float.floatToIntBits(f2);
923
924 return (thisBits == anotherBits ? 0 : // Values are equal
925 (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
926 1)); // (0.0, -0.0) or (NaN, !NaN)
927 }
928
929 /**
930 * Adds two {@code float} values together as per the + operator.
931 * Suitable for conversion as a method reference to functional interfaces such
932 * as {@code BinaryOperator<Float>}.
933 *
934 * @param a an argument.
935 * @param b another argument.
936 * @return the sum of {@code a} and {@code b}.
937 * @since 1.8
938 */
939 public static float sum(float a, float b) {
940 return a + b;
941 }
942
943 /**
944 * Returns the greater of two {@code float} values.
945 * Suitable for conversion as a method reference to functional interfaces such
946 * as {@code BinaryOperator<Float>}.
947 *
948 * @param a an argument.
949 * @param b another argument.
950 * @return the larger of {@code a} and {@code b}.
951 * @since 1.8
952 */
953 public static float max(float a, float b) {
954 return Math.max(a, b);
955 }
956
957 /**
958 * Returns the lesser of two {@code float} values.
959 * Suitable for conversion as a method reference to functional interfaces such
960 * as {@code BinaryOperator<Float>}.
961 *
962 * @param a an argument.
963 * @param b another argument.
964 * @return the lesser of {@code a} and {@code b}.
965 * @since 1.8
966 */
967 public static float min(float a, float b) {
968 return Math.min(a, b);
969 }
970
971 /** use serialVersionUID from JDK 1.0.2 for interoperability */
972 private static final long serialVersionUID = -2671257302660747028L;
973 }
|