Java Double Number Equal doubleEqual(double d1, double d2)

Here you can find the source of doubleEqual(double d1, double d2)

Description

Returns whether the two specified double value are equal.

License

Open Source License

Parameter

Parameter Description
d1 The first double to compare
d2 The second double to compare

Return

true if the two values are equal, otherwise false

Declaration

public static boolean doubleEqual(double d1, double d2) 

Method Source Code

//package com.java2s;
/*/*  w  w w. j  a v  a 2s.co m*/
 *   Copyright 2011 Calytrix Technologies
 *
 *   This file is part of Calytrix Disco.
 *
 *   Calytrix Disco is free software; you can redistribute it and/or modify
 *   it under the terms of the Common Developer and Distribution License (CDDL) 
 *   as published by Sun Microsystems. For more information see the LICENSE file.
 *   
 *   Use of this software is strictly AT YOUR OWN RISK!!!
 *   If something bad happens you do not have permission to come crying to me.
 *   (that goes for your lawyer as well)
 *
 */

public class Main {
    public static final double FP_EQUALITY_THRESHOLD = 1e-5;

    /**
     * Returns whether the two specified double value are equal. The two values
     * will be considered equal if the absolute difference between the values
     * is within a predefined threshold.
     * 
     * @param d1 The first double to compare
     * @param d2 The second double to compare
     * 
     * @return true if the two values are equal, otherwise false
     */
    public static boolean doubleEqual(double d1, double d2) {
        double absDiff = Math.abs(d1 - d2);
        return absDiff < FP_EQUALITY_THRESHOLD;
    }
}

Related

  1. doubleEqual(double d1, double d2, double delta)
  2. doubleEqual(double v1, double v2)
  3. doubleEquality(double v1, double v2, double epsilon)
  4. doubleEquals(double a, double b)