|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.math.ArithUtils
public class ArithUtils
Basic numeric operations not included in standard Java run-time library.
The binomial methods are modified from those in the Colt library.
The following methods for trigonometric functions come from the Sfun class written by Visual Numerics.
These methods are covered by the following license.
------------------------------------------------------------------------- $Id: Sfun.java,v 1.1.1.1 1999/03/05 21:43:39 brophy Exp $ ------------------------------------------------------------------------- Copyright (c) 1997 - 1998 by Visual Numerics, Inc. All rights reserved. Permission to use, copy, modify, and distribute this software is freely granted by Visual Numerics, Inc., provided that the copyright notice above and the following warranty disclaimer are preserved in human readable form. Because this software is licenses free of charge, it is provided "AS IS", with NO WARRANTY. TO THE EXTENT PERMITTED BY LAW, VNI DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. VNI WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -------------------------------------------------------------------------
Field Summary | |
---|---|
static double |
EPSILON_LARGE
The largest relative spacing for doubles. |
static double |
EPSILON_SMALL
The smallest relative spacing for doubles. |
Constructor Summary | |
---|---|
protected |
ArithUtils()
|
Method Summary | |
---|---|
static double |
acosh(double x)
Return the inverse (arc) hyperbolic cosine of a double. |
static boolean |
areEqual(double a,
double b)
Check if two doubles are equal to machine precision. |
static boolean |
areEqual(double a,
double b,
double tolerance)
Check if two doubles are equal to specified tolerance. |
static double |
asinh(double x)
Return the inverse (arc) hyperbolic sine of a double. |
static double |
atanh(double x)
Returns the inverse (arc) hyperbolic tangent of a double. |
static double |
binomial(double n,
long k)
Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k". |
static double |
binomial(long n,
long k)
Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k". |
static double |
cosh(double x)
Return the hyperbolic cosine of a double. |
static double |
cot(double x)
Return the contangent of a double. |
static int |
fuzzyCompare(double a,
double b,
double tolerance)
Perform fuzzy comparison of two doubles with specified tolerance. |
static double |
hypot(double a,
double b)
Safely calculate hypotenuse value. |
static boolean |
isNegativeZero(double x)
Check if number is negative zero. |
static double |
log10(double x)
Get log base 10 of a double. |
static double |
log2(double x)
Get log base 2 of a double. |
static double |
round(double x,
int n)
Round double to specified number of decimal places. |
static double |
safeLog(double x)
Return natural log of a double. |
static int |
sign(double d)
Return sign of a double. |
static double |
sign(double x,
double y)
Return the value of a double with the sign of another double. |
static int |
sign(int n)
Return sign of an integer. |
static double |
sinh(double x)
Compute hyperbolic sine of a double. |
static double |
tanh(double x)
Return the hyperbolic tangent of a double. |
static double |
trunc(double x)
Return the integer portion of a double as a double. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double EPSILON_SMALL
public static final double EPSILON_LARGE
Constructor Detail |
---|
protected ArithUtils()
Method Detail |
---|
public static double acosh(double x)
x
- Double whose inverse hyperbolic cosine is desired.
If x is NaN or less than one, the result is NaN.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static boolean areEqual(double a, double b)
a
- First double.b
- Second double.
public static boolean areEqual(double a, double b, double tolerance)
a
- First double.b
- Second double.tolerance
- Tolerance.
public static double asinh(double x)
x
- The value whose inverse hyperbolic sine is desired.
If x is NaN, the result is NaN.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static double atanh(double x)
x
- The value whose inverse hyperbolic tangent is desired.
If x is NaN or |x|>1, the result is NaN.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static double binomial(double n, long k)
The binomial coefficient is defined as (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k ).
public static double binomial(long n, long k)
The binomial coefficient is defined as
public static double cosh(double x)
x
- The value whose hyperbolic cosine is desired.
If x is NaN, the result is NaN.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static double cot(double x)
x
- The number whose cotangent is desired.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static int fuzzyCompare(double a, double b, double tolerance)
a
- First double.b
- Second double.tolerance
- Tolerance value.
This is an implementation of an algorithm suggested by Donald E. Knuth in Section 4.2.2 of Seminumerical Algorithms (3rd edition).
public static double hypot(double a, double b)
a
- One leg of triangle.b
- Second leg of triangle.
The hypotenuse value is given mathematically as the sqrt( a^2 + b^2 ). The method implemented here reduces the chances of cancellation and roundoff error. If the |a| > |b|, we compute the hypotenuse as:
hypotenuse = |a| * sqrt( 1 + (b/a) * (b/a) )
Otherwise b != 0 compute the hypotenuse as:
hypotenuse = |b| * sqrt( 1 + (a/b) * (a/b) )
If b is zero, the hypotenuse is zero.
public static boolean isNegativeZero(double x)
x
- The number to check.
public static double log2(double x)
x
- The number whose log base 2 value is desired.
Example: log2( 32 ) is 5.0D .
public static double log10(double x)
x
- The number whose log base 10 value is desired.
Example: log10( 100.0D ) is 2.0D .
public static double round(double x, int n)
x
- The double to round.n
- The number of decimal places to round to.
public static double safeLog(double x)
x
- The number whose natural log is desired.
public static int sign(int n)
n
- Number whose sign is desired.
public static int sign(double d)
d
- double whose sign is desired.
public static double sign(double x, double y)
x
- First double.y
- Second double.
public static double sinh(double x)
x
- The number whose hyperbolic sine is desired.
This method is a modified version of the one in the Visual Numerics Sfun class.
public static double trunc(double x)
x
- The double whose integer portion is to be found.
Example: trunc( 30.12345D ) is 30.0D .
public static double tanh(double x)
x
- The value whose hyperbolic tangent is desired.
This method is a modified version of the one in the Visual Numerics Sfun class.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |