Package org.apache.commons.numbers.gamma
Class SpecialMath
java.lang.Object
org.apache.commons.numbers.gamma.SpecialMath
Special math functions.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
2^-12.private static final double
2^-20.private static final double
2^-53.private static final double
2^-6.private static final double
High threshold to use log1p(x) - x.private static final double
Low threshold to use log1p(x) - x.private static final double
Minimum x for log1pmx(x). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double
log1pmx
(double x) Returnslog(1 + x) - x
.private static double
log1pmxSmall
(double x, double a) Returnslog(1 + x) - x
.
-
Field Details
-
X_MIN
private static final double X_MINMinimum x for log1pmx(x).- See Also:
-
X_LOW
private static final double X_LOWLow threshold to use log1p(x) - x.- See Also:
-
X_HIGH
private static final double X_HIGHHigh threshold to use log1p(x) - x.- See Also:
-
TWO_POW_M6
private static final double TWO_POW_M62^-6.- See Also:
-
TWO_POW_M12
private static final double TWO_POW_M122^-12.- See Also:
-
TWO_POW_M20
private static final double TWO_POW_M202^-20.- See Also:
-
TWO_POW_M53
private static final double TWO_POW_M532^-53.- See Also:
-
-
Constructor Details
-
SpecialMath
private SpecialMath()Private constructor.
-
-
Method Details
-
log1pmx
static double log1pmx(double x) Returnslog(1 + x) - x
. This function is accurate whenx -> 0
.This function uses a Taylor series expansion when x is small (
|x| < 0.01
):ln(1 + x) - x = -x^2/2 + x^3/3 - x^4/4 + ...
or around 0 (
-0.791 <= x <= 1
):ln(x + a) = ln(a) + 2 [z + z^3/3 + z^5/5 + z^7/7 + ... ] z = x / (2a + x)
For a = 1:
ln(x + 1) - x = -x + 2 [z + z^3/3 + z^5/5 + z^7/7 + ... ] = z * (-x + 2z^2 [ 1/3 + z^2/5 + z^4/7 + ... ])
The code is based on the
log1pmx
documentation for the R DPQ package with addition of the direct Taylor series for tiny x.See Abramowitz, M. and Stegun, I. A. (1972) Handbook of Mathematical Functions. New York: Dover. Formulas 4.1.24 and 4.2.29, p.68. Wikipedia: Abramowitz_and_Stegun provides links to the full text which is in public domain.
- Parameters:
x
- Value x- Returns:
log(1 + x) - x
-
log1pmxSmall
private static double log1pmxSmall(double x, double a) Returnslog(1 + x) - x
. This function is accurate whenx -> 0
.This function uses a Taylor series expansion when x is small (
|x| < 0.01
):ln(1 + x) - x = -x^2/2 + x^3/3 - x^4/4 + ...
No loop iterations are used as the series is directly expanded for a set number of terms based on the absolute value of x.
- Parameters:
x
- Value x (assumed to be small)a
- Absolute value of x- Returns:
log(1 + x) - x
-