org.apache.commons.math.util
Class Precision

java.lang.Object
  extended by org.apache.commons.math.util.Precision

public class Precision
extends java.lang.Object

Utilities for comparing numbers.

Since:
3.0
Version:
$Id$

Method Summary
static int compareTo(double x, double y, double eps)
          Compares two numbers given some amount of allowed error.
static int compareTo(double x, double y, int maxUlps)
          Compares two numbers given some amount of allowed error.
static boolean equals(double x, double y)
          Returns true iff they are equal as defined by equals(x, y, 1).
static boolean equals(double x, double y, double eps)
          Returns true if there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive).
static boolean equals(double x, double y, int maxUlps)
          Returns true if both arguments are equal or within the range of allowed error (inclusive).
static boolean equals(float x, float y)
          Returns true iff they are equal as defined by equals(x, y, 1).
static boolean equals(float x, float y, float eps)
          Returns true if both arguments are equal or within the range of allowed error (inclusive).
static boolean equals(float x, float y, int maxUlps)
          Returns true if both arguments are equal or within the range of allowed error (inclusive).
static boolean equalsIncludingNaN(double x, double y)
          Returns true if both arguments are NaN or neither is NaN and they are equal as defined by equals(x, y, 1).
static boolean equalsIncludingNaN(double x, double y, double eps)
          Returns true if both arguments are NaN or are equal or within the range of allowed error (inclusive).
static boolean equalsIncludingNaN(double x, double y, int maxUlps)
          Returns true if both arguments are NaN or if they are equal as defined by equals(x, y, maxUlps).
static boolean equalsIncludingNaN(float x, float y)
          Returns true if both arguments are NaN or neither is NaN and they are equal as defined by equals(x, y, 1).
static boolean equalsIncludingNaN(float x, float y, float eps)
          Returns true if both arguments are NaN or are equal or within the range of allowed error (inclusive).
static boolean equalsIncludingNaN(float x, float y, int maxUlps)
          Returns true if both arguments are NaN or if they are equal as defined by equals(x, y, maxUlps).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compareTo

public static int compareTo(double x,
                            double y,
                            double eps)
Compares two numbers given some amount of allowed error.

Parameters:
x - the first number
y - the second number
eps - the amount of error to allow when checking for equality
Returns:

compareTo

public static int compareTo(double x,
                            double y,
                            int maxUlps)
Compares two numbers given some amount of allowed error. Two float numbers are considered equal if there are (maxUlps - 1) (or fewer) floating point numbers between them, i.e. two adjacent floating point numbers are considered equal. Adapted from Bruce Dawson

Parameters:
x - first value
y - second value
maxUlps - (maxUlps - 1) is the number of floating point values between x and y.
Returns:

equals

public static boolean equals(float x,
                             float y)
Returns true iff they are equal as defined by equals(x, y, 1).

Parameters:
x - first value
y - second value
Returns:
true if the values are equal.

equalsIncludingNaN

public static boolean equalsIncludingNaN(float x,
                                         float y)
Returns true if both arguments are NaN or neither is NaN and they are equal as defined by equals(x, y, 1).

Parameters:
x - first value
y - second value
Returns:
true if the values are equal or both are NaN.
Since:
2.2

equals

public static boolean equals(float x,
                             float y,
                             float eps)
Returns true if both arguments are equal or within the range of allowed error (inclusive).

Parameters:
x - first value
y - second value
eps - the amount of absolute error to allow.
Returns:
true if the values are equal or within range of each other.
Since:
2.2

equalsIncludingNaN

public static boolean equalsIncludingNaN(float x,
                                         float y,
                                         float eps)
Returns true if both arguments are NaN or are equal or within the range of allowed error (inclusive).

Parameters:
x - first value
y - second value
eps - the amount of absolute error to allow.
Returns:
true if the values are equal or within range of each other, or both are NaN.
Since:
2.2

equals

public static boolean equals(float x,
                             float y,
                             int maxUlps)
Returns true if both arguments are equal or within the range of allowed error (inclusive). Two float numbers are considered equal if there are (maxUlps - 1) (or fewer) floating point numbers between them, i.e. two adjacent floating point numbers are considered equal. Adapted from Bruce Dawson

Parameters:
x - first value
y - second value
maxUlps - (maxUlps - 1) is the number of floating point values between x and y.
Returns:
true if there are fewer than maxUlps floating point values between x and y.
Since:
2.2

equalsIncludingNaN

public static boolean equalsIncludingNaN(float x,
                                         float y,
                                         int maxUlps)
Returns true if both arguments are NaN or if they are equal as defined by equals(x, y, maxUlps).

Parameters:
x - first value
y - second value
maxUlps - (maxUlps - 1) is the number of floating point values between x and y.
Returns:
true if both arguments are NaN or if there are less than maxUlps floating point values between x and y.
Since:
2.2

equals

public static boolean equals(double x,
                             double y)
Returns true iff they are equal as defined by equals(x, y, 1).

Parameters:
x - first value
y - second value
Returns:
true if the values are equal.

equalsIncludingNaN

public static boolean equalsIncludingNaN(double x,
                                         double y)
Returns true if both arguments are NaN or neither is NaN and they are equal as defined by equals(x, y, 1).

Parameters:
x - first value
y - second value
Returns:
true if the values are equal or both are NaN.
Since:
2.2

equals

public static boolean equals(double x,
                             double y,
                             double eps)
Returns true if there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive).

Parameters:
x - First value.
y - Second value.
eps - Amount of allowed absolute error.
Returns:
true if the values are two adjacent floating point numbers or they are within range of each other.

equalsIncludingNaN

public static boolean equalsIncludingNaN(double x,
                                         double y,
                                         double eps)
Returns true if both arguments are NaN or are equal or within the range of allowed error (inclusive).

Parameters:
x - first value
y - second value
eps - the amount of absolute error to allow.
Returns:
true if the values are equal or within range of each other, or both are NaN.
Since:
2.2

equals

public static boolean equals(double x,
                             double y,
                             int maxUlps)
Returns true if both arguments are equal or within the range of allowed error (inclusive). Two float numbers are considered equal if there are (maxUlps - 1) (or fewer) floating point numbers between them, i.e. two adjacent floating point numbers are considered equal. Adapted from Bruce Dawson

Parameters:
x - first value
y - second value
maxUlps - (maxUlps - 1) is the number of floating point values between x and y.
Returns:
true if there are fewer than maxUlps floating point values between x and y.

equalsIncludingNaN

public static boolean equalsIncludingNaN(double x,
                                         double y,
                                         int maxUlps)
Returns true if both arguments are NaN or if they are equal as defined by equals(x, y, maxUlps).

Parameters:
x - first value
y - second value
maxUlps - (maxUlps - 1) is the number of floating point values between x and y.
Returns:
true if both arguments are NaN or if there are less than maxUlps floating point values between x and y.
Since:
2.2


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.