Here you can find the source of between(double valueToCompare, double leftBoundary, double rightBoundary, double epsilon)
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] |
public static boolean between(double valueToCompare, double leftBoundary, double rightBoundary, double epsilon)
//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; } }