public final class ElementaryFunction
extends java.lang.Object
Utility case for defining elementary mathematical functions that are not, but should be,
included in the java.lang.Math
class. Several of the functions in this
class are implemented using the methods of java.lang.Math
.
Math
,
StrictMath
Modifier and Type | Field and Description |
---|---|
static double |
EPS
small tolerance value
|
static double |
PI_BY_2
the value PI/2
|
static int |
ULPS_BRACKET
number of Units in the Last Place (ULPs) used for bracketing approximately equal values
|
Constructor and Description |
---|
ElementaryFunction() |
Modifier and Type | Method and Description |
---|---|
static double |
acosh(double x)
Inverse hyperbolic cosine function.
|
static boolean |
approxEq(double x,
double y)
Test if two
double precision numbers are approximately equal. |
static boolean |
approxEq(double x,
double y,
int cntUlps)
Test if two
double precision numbers are approximately equal. |
static double |
asinh(double x)
Inverse hyperbolic sine function.
|
static double |
atanh(double x)
Inverse hyperbolic tangent function.
|
static double |
cosh(double x)
Hyperbolic cosine function.
|
static int |
factorial(int n)
Computes the factorial of the given integer.
|
static boolean |
neighbors(double x,
double y,
double r)
Test if two
double precision numbers are in the same ball
of radius r. |
static double |
pow(double dblBase,
int intExpon)
Returns the value of the first argument raised to the power of the second argument
dblBasedblExpon.
|
static long |
pow(int intBase,
int intExpon)
Returns the value of the first argument raised to the power of the second argument
intBaseintExpon where the base is an integer.
|
static double |
sinc(double x)
Implementation of the sinc function where
sinc(x) ≡ sin(x)/x. |
static double |
sinch(double x)
Implementation of the sinch function where
sinch(x) ≡ sinh(x)/x |
static double |
sinchm(double x)
Returns the sinch(x2).
|
static double |
sinh(double x)
Hyperbolic sine function.
|
static double |
tanh(double x)
Hyperbolic tangent function.
|
public static final int ULPS_BRACKET
public static final double PI_BY_2
public static final double EPS
public static boolean approxEq(double x, double y)
double
precision numbers are approximately equal.
This condition is checked using the the default number of Units in the
Last Place (ULPs) bracketing the two numbers.x
- double precision numbery
- double precision numberpublic static boolean approxEq(double x, double y, int cntUlps)
double
precision numbers are approximately equal.
This condition is checked using the the number of Units in the Last Place
(ULPs) bracketing the two numbers.x
- double precision numbery
- double precision numbercntUlps
- number of ULPs used to bracket the numberspublic static boolean neighbors(double x, double y, double r)
double
precision numbers are in the same ball
of radius r.x
- double precision numbery
- double precision numberpublic static final int factorial(int n)
n
- integer to be "factorialized"public static final double pow(double dblBase, int intExpon)
Returns the value of the first argument raised to the power of the second argument
dblBasedblExpon. Special cases:
· If the second argument is positive or negative zero, then the result is 1.0.
· If the second argument is 1.0, then the result is the same as the first argument.
· If the second argument is NaN, then the result is NaN.
· If the first argument is NaN and the second argument is nonzero, then the result is NaN.
This method should be used over that of
whenever the
exponent is an integer. Since the later must consider the case of non-integer exponents the
algorithm used there is more expensive than the simple multiplication used here.
Math.pow(double, double)
dblBase
- the base of the exponentialintExpon
- the exponentpublic static final long pow(int intBase, int intExpon)
Returns the value of the first argument raised to the power of the second argument
intBaseintExpon where the base is an integer. Special cases:
· If the second argument is positive or negative zero, then the result is 1.
· If the second argument is 1, then the result is the same as the first argument.
· If the second argument is NaN, then the result is NaN.
· If the first argument is NaN and the second argument is nonzero, then the result is NaN.
This method should be used over that of
whenever both the
base and the exponent are integers. Since the later must consider the case of non-integer exponents the
algorithm used here is less expensive.
Math.pow(double, double)
intBase
- the base of the exponentialintExpon
- the exponentpublic static double sinc(double x)
Implementation of the sinc function where
sinc(x) ≡ sin(x)/x.
For small values of x we Taylor expand the sinc
function to sixth order,
sinc(x) ≈ 1 - x2/6 +
x4/120 -
x6/5040 +
O(x8).
otherwise we return sin(x)/x.
x
- any real numberpublic static double sinch(double x)
Implementation of the sinch function where
sinch(x) ≡ sinh(x)/x
For small values of x we Taylor expand the hyperbolic
sine function to sixth order,
sinch(x) ≈ 1 + x2/6 +
x4/120 +
x6/5040 +
O(x8).
Otherwise we return sinh(x)/x.
x
- any real numberpublic static double sinchm(double x)
x
- any real numbersinch(double)
public static final double sinh(double x)
x
- any real numberpublic static final double cosh(double x)
x
- any real numberpublic static final double tanh(double x)
public static final double asinh(double x)
x
- any real numberpublic static final double acosh(double x) throws java.lang.IllegalArgumentException
x
- a real number in the interval [1,+∞)java.lang.IllegalArgumentException
- argument value is outside the domain of definitionpublic static final double atanh(double x) throws java.lang.IllegalArgumentException
x
- a real number in the open interval (-1,1)java.lang.IllegalArgumentException
- argument value is outside the domain of definition