Here you can find the source of equal(float val1, float val2)
Parameter | Description |
---|---|
val1 | the first value, may be null |
val2 | the second value, may be null |
public static boolean equal(float val1, float val2)
//package com.java2s; /*/*from ww w . ja v a 2s .c o m*/ * Copyright 2001-2014 Stephen Colebourne * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Arrays; public class Main { /** * Checks if two objects are equal handling null. * * @param obj1 the first object, may be null * @param obj2 the second object, may be null * @return true if equal */ public static boolean equal(Object obj1, Object obj2) { if (obj1 == obj2) { return true; } if (obj1 == null || obj2 == null) { return false; } if (obj1.getClass().isArray() && obj1.getClass() == obj2.getClass()) { if (obj1 instanceof Object[] && obj2 instanceof Object[]) { return Arrays.deepEquals((Object[]) obj1, (Object[]) obj2); } else if (obj1 instanceof int[] && obj2 instanceof int[]) { return Arrays.equals((int[]) obj1, (int[]) obj2); } else if (obj1 instanceof long[] && obj2 instanceof long[]) { return Arrays.equals((long[]) obj1, (long[]) obj2); } else if (obj1 instanceof byte[] && obj2 instanceof byte[]) { return Arrays.equals((byte[]) obj1, (byte[]) obj2); } else if (obj1 instanceof double[] && obj2 instanceof double[]) { return Arrays.equals((double[]) obj1, (double[]) obj2); } else if (obj1 instanceof float[] && obj2 instanceof float[]) { return Arrays.equals((float[]) obj1, (float[]) obj2); } else if (obj1 instanceof char[] && obj2 instanceof char[]) { return Arrays.equals((char[]) obj1, (char[]) obj2); } else if (obj1 instanceof short[] && obj2 instanceof short[]) { return Arrays.equals((short[]) obj1, (short[]) obj2); } else if (obj1 instanceof boolean[] && obj2 instanceof boolean[]) { return Arrays.equals((boolean[]) obj1, (boolean[]) obj2); } } // this does not handle arrays embedded in objects, such as in lists/maps // but you shouldn't use arrays like that, should you? return obj1.equals(obj2); } /** * Checks if two floats are equal based on identity. * <p> * This performs the same check as {@link Float#equals(Object)}. * * @param val1 the first value, may be null * @param val2 the second value, may be null * @return true if equal */ public static boolean equal(float val1, float val2) { return Float.floatToIntBits(val1) == Float.floatToIntBits(val2); } /** * Checks if two doubles are equal based on identity. * <p> * This performs the same check as {@link Double#equals(Object)}. * * @param val1 the first value, may be null * @param val2 the second value, may be null * @return true if equal */ public static boolean equal(double val1, double val2) { return Double.doubleToLongBits(val1) == Double.doubleToLongBits(val2); } }