Here you can find the source of doubleEquality(double v1, double v2, double epsilon)
Parameter | Description |
---|---|
v1 | double no. 1 |
v2 | double no. 2 |
epsilon | an user-defined epsilon |
public static boolean doubleEquality(double v1, double v2, double epsilon)
//package com.java2s; /*/* w w w .j a va 2 s.c om*/ * The MIT License * * Copyright 2015 Hilmar. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ public class Main { /** * the standard-epsilon for the double-equality check */ private static double epsilonDoubleEq = 0.00001; /** * a pseudo-equality check for doubles * * @param v1 double no. 1 * @param v2 double no. 2 * @return true, if they are pseudo-equal */ public static boolean doubleEquality(double v1, double v2) { return Math.abs(v1 - v2) < epsilonDoubleEq; } /** * a pseudo-equality check for doubles * * @param v1 double no. 1 * @param v2 double no. 2 * @param epsilon an user-defined epsilon * @return true, if they are pseudo-equal */ public static boolean doubleEquality(double v1, double v2, double epsilon) { return Math.abs(v1 - v2) < epsilon; } }