jopt.csp.util
Class FloatUtil

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

public class FloatUtil
extends java.lang.Object

Float type utility functions


Field Summary
static float DEFAULT_PRECISION
           
 
Constructor Summary
FloatUtil()
           
 
Method Summary
static int compare(float val1, float val2, float precision)
          Compares two values using a given precision to determine if they are equal
static float getMax(CspNumExpr expr)
          Returns maximum value of a numeric expression as a float type
static float getMax(VariableSolution sol)
          Returns maximum value of a numeric expression as a double type
static float getMin(CspNumExpr expr)
          Returns minimum value of a numeric expression as a float type
static float getMin(VariableSolution sol)
          Returns minimum value of a numeric expression as a double type
static int intCeil(float n)
          Returns integer value for a number rounding using ceiling method if necessary
static int intFloor(float n)
          Returns integer value for a number rounding using floor method if necessary
static boolean isEqual(float val1, float val2, float precision)
          Returns true if two values are within precision of one another
static boolean isIntEquivalent(float val)
          Returns true if value is equivalent to an integer value
static boolean isLongEquivalent(float val)
          Returns true if value is equivalent to a long value
static long longCeil(float n)
          Returns long value for a number rounding using ceiling method if necessary
static long longFloor(float n)
          Returns long value for a number rounding using floor method if necessary
static float next(float v)
          Returns the next float value in sequence for a given float
static float previous(float v)
          Returns the previous float value in sequence for a given float
static float returnMinMaxIfClose(float minCurrent, float maxCurrent, float newVal, float precision)
          Returns a min or max value if it 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 float DEFAULT_PRECISION
See Also:
Constant Field Values
Constructor Detail

FloatUtil

public FloatUtil()
Method Detail

next

public static float next(float v)
Returns the next float value in sequence for a given float


previous

public static float previous(float v)
Returns the previous float value in sequence for a given float


returnMinMaxIfClose

public static float returnMinMaxIfClose(float minCurrent,
                                        float maxCurrent,
                                        float newVal,
                                        float precision)
Returns a min or max value if it 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(float val1,
                          float val2,
                          float 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(float val1,
                              float val2,
                              float precision)
Returns true if two values are within precision of one another

Parameters:
val1 - First value to compare
val2 - Second value to compare
precision - Precision values must fall within to return true.

intCeil

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


intFloor

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


isIntEquivalent

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


longCeil

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


longFloor

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


isLongEquivalent

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


getMin

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


getMax

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


getMin

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


getMax

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