Java Double Number Between between(double valueToCompare, double leftBoundary, double rightBoundary, double epsilon)

Here you can find the source of between(double valueToCompare, double leftBoundary, double rightBoundary, double epsilon)

Description

Checks if a value is between two parameters with respect to a little error (epsilon)

License

Open Source License

Parameter

Parameter Description
valueToCompare The value to check [e.g. 0.5]
leftBoundary The left boundary [e.g. 0]
rightBoundary The right boundary [e.g. 1]
epsilon The error epsilon [e.g 0.01]

Return

if the value is between the parameters with respect to epsilon, otherwise

Declaration

public static boolean between(double valueToCompare, double leftBoundary, double rightBoundary,
        double epsilon) 

Method Source Code

//package com.java2s;
/*/*from  w w  w.j a  v  a2  s . c  o  m*/
 * jCase - Java Combinatorial Auction Simulator 
 * Copyright (C) 2004-2006 Bjoern Schnizler, University of Karlsruhe (TH)
 * http://www.iw.uni-karlsruhe.de/jcase
 *
 * Parts of this work are funded by the European Union
 * under the IST project CATNETS (http://www.catnets.org/)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or any later version.
 * See the GNU General Public License for more details.
 *
 * This code comes WITHOUT ANY WARRANTY
 */

public class Main {
    /**
     * Checks if a value is between two parameters with respect to a little
     * error (epsilon)
     * 
     * @param valueToCompare
     *            The value to check [e.g. 0.5]
     * @param leftBoundary
     *            The left boundary [e.g. 0]
     * @param rightBoundary
     *            The right boundary [e.g. 1]
     * @param epsilon
     *            The error epsilon [e.g 0.01]
     * @return <true> if the value is between the parameters with respect to
     *         epsilon, <false> otherwise
     */
    public static boolean between(double valueToCompare, double leftBoundary, double rightBoundary,
            double epsilon) {
        if (valueToCompare == leftBoundary || valueToCompare == rightBoundary)
            return true;
        if (valueToCompare >= leftBoundary && valueToCompare <= rightBoundary)
            return true;
        if (valueToCompare + epsilon < leftBoundary)
            return false;
        if (valueToCompare > rightBoundary + epsilon)
            return false;
        return true;
    }
}

Related

  1. between(double value, double end1, double end2)
  2. between(double value, double min, double max)
  3. between(double value, double min, double max)
  4. between(double value, double value1, double value2)
  5. between(double value1, double value2, double valueObj)
  6. between(final double zScore, final int firstIndex, final int secondIndex)
  7. betweenOrEqual(double max, double min, double val)