jopt.csp.util
Class DoubleUtil

java.lang.Object
  extended byjopt.csp.util.DoubleUtil

public class DoubleUtil
extends java.lang.Object

Double type utility functions


Field Summary
static double DEFAULT_PRECISION
           
 
Constructor Summary
DoubleUtil()
           
 
Method Summary
static int compare(double val1, double val2, double precision)
          Compares two values using a given precision to determine if they are equal
static double getMax(CspNumExpr expr)
          Returns maximum value of a numeric expression as a double type
static double getMax(VariableSolution sol)
          Returns maximum value of a numeric expression as a double type
static double getMin(CspNumExpr expr)
          Returns minimum value of a numeric expression as a double type
static double getMin(VariableSolution sol)
          Returns minimum value of a numeric expression as a double type
static int intCeil(double n)
          Returns integer value for a number rounding using ceiling method if necessary
static int intFloor(double n)
          Returns integer value for a number rounding using floor method if necessary
static boolean isEqual(double val1, double val2, double precision)
          Returns true if two values are within precision of one another.
static boolean isIntEquivalent(double val)
          Returns true if value is equivalent to an integer value
static boolean isLongEquivalent(double val)
          Returns true if value is equivalent to a long value
static long longCeil(double n)
          Returns long value for a number rounding using ceiling method if necessary
static long longFloor(double n)
          Returns long value for a number rounding using floor method if necessary
static double next(double v)
          Returns the next higher (towards positive infinity) double precision floating-point value.
static double previous(double v)
          Returns the next lower (towards negative infinity) double precision floating-point value.
static double returnMinMaxIfClose(double minCurrent, double maxCurrent, double newVal, double precision)
          Returns a min or max value if it is close enough to a value for comparison based on a precision value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PRECISION

public static final double DEFAULT_PRECISION
See Also:
Constant Field Values
Constructor Detail

DoubleUtil

public DoubleUtil()
Method Detail

next

public static double next(double v)
Returns the next higher (towards positive infinity) double precision floating-point value.


previous

public static double previous(double v)
Returns the next lower (towards negative infinity) double precision floating-point value.


returnMinMaxIfClose

public static double returnMinMaxIfClose(double minCurrent,
                                         double maxCurrent,
                                         double newVal,
                                         double precision)
Returns a min or max value if it is close enough to a value for comparison based on a precision value

Parameters:
minCurrent - Minimum possible current value that will be returned if new value is close enough given scale
maxCurrent - Maximum possible current value that will be returned if new value is close enough given scale
newVal - Value that is to be checked to ensure it is close enough to another value
precision - Precision values must fall within to be equal

compare

public static int compare(double val1,
                          double val2,
                          double precision)
Compares two values using a given precision to determine if they are equal

Parameters:
val1 - First value to compare
val2 - Second value to compare
precision - Precision values must fall within to be equal

isEqual

public static boolean isEqual(double val1,
                              double val2,
                              double precision)
Returns true if two values are within precision of one another. Precision value should be less than 0.1 or else this procedure doesn't make sense. Negative and positive infinity are considered equal to -Double.MAX_VALUE and Double.MAX_VALUE respectively.

Parameters:
val1 - First value to compare
val2 - Second value to compare
precision - Precision values must fall within to return true. When comparing values where at least one of them is of magnitude less than one, this is an absolute precision: a simple difference. When comparing values both greater than one, this is a fractional error not an absolute plus or minus bounds. Therefore 1,000,000 and 1,000,001 are equal if precision is set to .000002.

intCeil

public static int intCeil(double n)
Returns integer value for a number rounding using ceiling method if necessary


intFloor

public static int intFloor(double n)
Returns integer value for a number rounding using floor method if necessary


isIntEquivalent

public static boolean isIntEquivalent(double val)
Returns true if value is equivalent to an integer value


longCeil

public static long longCeil(double n)
Returns long value for a number rounding using ceiling method if necessary


longFloor

public static long longFloor(double n)
Returns long value for a number rounding using floor method if necessary


isLongEquivalent

public static boolean isLongEquivalent(double val)
Returns true if value is equivalent to a long value


getMin

public static double getMin(CspNumExpr expr)
Returns minimum value of a numeric expression as a double type


getMax

public static double getMax(CspNumExpr expr)
Returns maximum value of a numeric expression as a double type


getMin

public static double getMin(VariableSolution sol)
Returns minimum value of a numeric expression as a double type


getMax

public static double getMax(VariableSolution sol)
Returns maximum value of a numeric expression as a double type