Java Float Number Equal equals(float f1, float f2)

Here you can find the source of equals(float f1, float f2)

Description

equals

License

Open Source License

Declaration

public static boolean equals(float f1, float f2) 

Method Source Code

//package com.java2s;
/**/*from  ww  w.  jav a  2  s .co  m*/
 * This file is protected by Copyright. 
 * Please refer to the COPYRIGHT file distributed with this source distribution.
 * 
 * This file is part of REDHAWK IDE.
 * 
 * All rights reserved.  This program and the accompanying materials are made available under 
 * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html.
 *
 */

import java.util.Arrays;

public class Main {
    /**
     * @since 1.2
     */
    public static boolean equals(final Object left, final Object right) {
        if (left == right) {
            return true;
        } else if (left == null) {
            return false;
        } else {
            if (right == null) {
                return false;
            } else if (left.getClass() != right.getClass()) {
                return false;
            } else if (left instanceof Object[]) {
                return Arrays.deepEquals((Object[]) left, (Object[]) right);
            } else if (left instanceof byte[]) {
                return Arrays.equals((byte[]) left, (byte[]) right);
            } else if (left instanceof char[]) {
                return Arrays.equals((char[]) left, (char[]) right);
            } else if (left instanceof short[]) {
                return Arrays.equals((short[]) left, (short[]) right);
            } else if (left instanceof int[]) {
                return Arrays.equals((int[]) left, (int[]) right);
            } else if (left instanceof long[]) {
                return Arrays.equals((long[]) left, (long[]) right);
            } else if (left instanceof float[]) {
                return Arrays.equals((float[]) left, (float[]) right);
            } else if (left instanceof double[]) {
                return Arrays.equals((double[]) left, (double[]) right);
            } else if (left instanceof boolean[]) {
                return Arrays.equals((boolean[]) left, (boolean[]) right);
            } else {
                return left.equals(right);
            }
        }
    }

    /**
     * @since 3.3
     */
    public static boolean equals(float f1, float f2) {
        return Math.abs(f1 - f2) < 0.0000001f;
    }

    /**
     * @since 3.3
     */
    public static boolean equals(double d1, double d2) {
        return Math.abs(d1 - d2) < 0.0000001d;
    }
}

Related

  1. areFloatsEqual(float f1, float f2)
  2. areFloatsEqual(float f1, float f2)
  3. areFloatsEqual(Float one, Float two)
  4. equal(float val1, float val2)
  5. floatEqual(float a, float b, float epsilon)
  6. floatEqual(float f1, float f2)
  7. floatEquals(float a, float b)
  8. floatEquals(float x, float y)