org.deri.iris.utils
Class StrictFloatingPointComparator

java.lang.Object
  extended by org.deri.iris.utils.StrictFloatingPointComparator
All Implemented Interfaces:
IFloatingPointComparator

public class StrictFloatingPointComparator
extends Object
implements IFloatingPointComparator

A floating point comparator that uses the default java behaviour. This class will make floating point comparison faster, but will not allow for any round-off errors at all.


Constructor Summary
StrictFloatingPointComparator()
           
 
Method Summary
 int compare(double a, double b)
          An error-safe comparison in the java style.
 boolean equals(double a, double b)
          Test two double values for equality.
 boolean greater(double a, double b)
          Floating-point error safe comparison.
 boolean greaterOrEquals(double a, double b)
          Floating-point error safe comparison.
 boolean isIntValue(double value)
          Indicates whether a double value contains an integer or a number very, very close to an integer.
 boolean less(double a, double b)
          Floating-point error safe comparison.
 boolean lessOrEquals(double a, double b)
          Floating-point error safe comparison.
 boolean notEquals(double a, double b)
          Floating-point error safe comparison.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrictFloatingPointComparator

public StrictFloatingPointComparator()
Method Detail

compare

public int compare(double a,
                   double b)
Description copied from interface: IFloatingPointComparator
An error-safe comparison in the java style.

Specified by:
compare in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
-1 if a is significantly less than b, +1 if a is significantly greater than b, 0 if a and b are close enough.

equals

public boolean equals(double a,
                      double b)
Description copied from interface: IFloatingPointComparator
Test two double values for equality.

Specified by:
equals in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
true If a and b are considered equal.

greater

public boolean greater(double a,
                       double b)
Description copied from interface: IFloatingPointComparator
Floating-point error safe comparison.

Specified by:
greater in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
true If a is greater than b.

greaterOrEquals

public boolean greaterOrEquals(double a,
                               double b)
Description copied from interface: IFloatingPointComparator
Floating-point error safe comparison.

Specified by:
greaterOrEquals in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
true If a is greater than or close enough to be equal to b.

isIntValue

public boolean isIntValue(double value)
Description copied from interface: IFloatingPointComparator
Indicates whether a double value contains an integer or a number very, very close to an integer.

Specified by:
isIntValue in interface IFloatingPointComparator
Parameters:
value - The value to test
Returns:
true If value holds an integer.

less

public boolean less(double a,
                    double b)
Description copied from interface: IFloatingPointComparator
Floating-point error safe comparison.

Specified by:
less in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
true If a is less than b.

lessOrEquals

public boolean lessOrEquals(double a,
                            double b)
Description copied from interface: IFloatingPointComparator
Floating-point error safe comparison.

Specified by:
lessOrEquals in interface IFloatingPointComparator
Parameters:
a - A double value
b - A double value
Returns:
true If a is less than or close enough to be equal to b.

notEquals

public boolean notEquals(double a,
                         double b)
Description copied from interface: IFloatingPointComparator
Floating-point error safe comparison.

Specified by:
notEquals in interface IFloatingPointComparator
Returns:
true If a and b are significantly different.