Here you can find the source of doubleEqual(double d1, double d2)
Parameter | Description |
---|---|
d1 | The first double to compare |
d2 | The second double to compare |
public static boolean doubleEqual(double d1, double d2)
//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; } }