public class DfpMath extends Object
| Modifier and Type | Method | Description |
|---|---|---|
static Dfp |
acos(Dfp a) |
computes the arc-cosine of the argument.
|
static Dfp |
asin(Dfp a) |
computes the arc-sine of the argument.
|
static Dfp |
atan(Dfp a) |
computes the arc tangent of the argument
Uses the typical taylor series
but may reduce arguments using the following identity
tan(x+y) = (tan(x) + tan(y)) / (1 - tan(x)*tan(y))
since tan(PI/8) = sqrt(2)-1,
atan(x) = atan( (x - sqrt(2) + 1) / (1+x*sqrt(2) - x) + PI/8.0
|
protected static Dfp |
atanInternal(Dfp a) |
computes the arc-tangent of the argument.
|
static Dfp |
cos(Dfp a) |
computes the cosine of the argument.
|
protected static Dfp |
cosInternal(Dfp[] a) |
Computes cos(a) Used when
0 < a < pi/4. |
static Dfp |
exp(Dfp a) |
Computes e to the given power.
|
protected static Dfp |
expInternal(Dfp a) |
Computes e to the given power.
|
static Dfp |
log(Dfp a) |
Returns the natural logarithm of a.
|
protected static Dfp[] |
logInternal(Dfp[] a) |
Computes the natural log of a number between 0 and 2.
|
static Dfp |
pow(Dfp base,
int a) |
Raises base to the power a by successive squaring.
|
static Dfp |
pow(Dfp x,
Dfp y) |
Computes x to the y power.
|
static Dfp |
sin(Dfp a) |
computes the sine of the argument.
|
protected static Dfp |
sinInternal(Dfp[] a) |
Computes sin(a) Used when
{@code 0 < a < pi/4}. |
protected static Dfp[] |
split(Dfp a) |
|
protected static Dfp[] |
split(DfpField field,
String a) |
Breaks a string representation up into two dfp's.
|
protected static Dfp[] |
splitDiv(Dfp[] a,
Dfp[] b) |
Divide two numbers that are split in to two pieces that are meant to be added together.
|
protected static Dfp[] |
splitMult(Dfp[] a,
Dfp[] b) |
Multiply two numbers that are split in to two pieces that are
meant to be added together.
|
protected static Dfp |
splitPow(Dfp[] base,
int a) |
Raise a split base to the a power.
|
static Dfp |
tan(Dfp a) |
computes the tangent of the argument.
|
protected static Dfp[] split(DfpField field, String a)
The two dfp are such that the sum of them is equivalent to the input string, but has higher precision than using a single dfp. This is useful for improving accuracy of exponentiation and critical multiplies.
field - field to which the Dfp must belonga - string representation to splitDfp which sum is aprotected static Dfp[] split(Dfp a)
a - number to splitprotected static Dfp[] splitMult(Dfp[] a, Dfp[] b)
a - first factor of the multiplication, in split formb - second factor of the multiplication, in split formprotected static Dfp[] splitDiv(Dfp[] a, Dfp[] b)
a - dividend, in split formb - divisor, in split formprotected static Dfp splitPow(Dfp[] base, int a)
base - number to raisea - powerpublic static Dfp pow(Dfp base, int a)
base - number to raisea - powerpublic static Dfp exp(Dfp a)
a - power at which e should be raisedprotected static Dfp expInternal(Dfp a)
-1 < a < 1. Use the classic Taylor series.
1 + x**2/2! + x**3/3! + x**4/4! ... a - power at which e should be raisedpublic static Dfp log(Dfp a)
a = (10000^h)(2^j)k.
ln(a) is computed by ln(a) = ln(5)*h + ln(2)*(h+j) + ln(k).
k is in the range 2/3 < k <4/3 and is passed on to a series expansion.a - number from which logarithm is requestedprotected static Dfp[] logInternal(Dfp[] a)
Let f(x) = ln(x),
We know that f'(x) = 1/x, thus from Taylor's theorum we have:
----- n+1 n
f(x) = \ (-1) (x - 1)
/ ---------------- for 1 <= n <= infinity
----- n
or
2 3 4
(x-1) (x-1) (x-1)
ln(x) = (x-1) - ----- + ------ - ------ + ...
2 3 4
alternatively,
2 3 4
x x x
ln(x+1) = x - - + - - - + ...
2 3 4
This series can be used to compute ln(x), but it converges too slowly.
If we substitute -x for x above, we get
2 3 4
x x x
ln(1-x) = -x - - - - - - + ...
2 3 4
Note that all terms are now negative. Because the even powered ones
absorbed the sign. Now, subtract the series above from the previous
one to get ln(x+1) - ln(1-x). Note the even terms cancel out leaving
only the odd ones
3 5 7
2x 2x 2x
ln(x+1) - ln(x-1) = 2x + --- + --- + ---- + ...
3 5 7
By the property of logarithms that ln(a) - ln(b) = ln (a/b) we have:
3 5 7
x+1 / x x x \
* ln ----- = 2 * | x + ---- + ---- + ---- + ... |
x-1 \ 3 5 7 /
But now we want to find ln(a), so we need to find the value of x
such that a = (x+1)/(x-1). This is easily solved to find that
x = (a-1)/(a+1).
a - number from which logarithm is requested, in split formpublic static Dfp pow(Dfp x, Dfp y)
Uses the following method:
|y| > 1e8, then we compute by exp(y*ln(x))Special Cases
|x| > 1.0 and y is +Infinity then result is +Infinity
|x| < 1.0 and y is -Infinity then result is +Infinity
|x| > 1.0 and y is -Infinity then result is +0
|x| < 1.0 and y is +Infinity then result is +0
|x| = 1.0 and y is +/-Infinity then result is NaN
x = +0 and y > 0 then result is +0
x = +Inf and y < 0 then result is +0
x = +0 and y < 0 then result is +Inf
x = +Inf and y > 0 then result is +Inf
x = -0 and y > 0, finite, not odd integer then result is +0
x = -0 and y < 0, finite, and odd integer then result is -Inf
x = -Inf and y > 0, finite, and odd integer then result is -Inf
x = -0 and y < 0, not finite odd integer then result is +Inf
x = -Inf and y > 0, not finite odd integer then result is +Inf
x < 0 and y > 0, finite, and odd integer then result is -(|x|y)
x < 0 and y > 0, finite, and not integer then result is NaN
x - base to be raisedy - power to which base should be raisedprotected static Dfp sinInternal(Dfp[] a)
{@code 0 < a < pi/4}.
Uses the classic Taylor series. x - x**3/3! + x**5/5! ... a - number from which sine is desired, in split formprotected static Dfp cosInternal(Dfp[] a)
0 < a < pi/4.
Uses the classic Taylor series for cosine. 1 - x**2/2! + x**4/4! ...a - number from which cosine is desired, in split formpublic static Dfp sin(Dfp a)
a - number from which sine is desiredpublic static Dfp cos(Dfp a)
a - number from which cosine is desiredpublic static Dfp tan(Dfp a)
a - number from which tangent is desiredprotected static Dfp atanInternal(Dfp a)
a - number from which arc-tangent is desiredpublic static Dfp atan(Dfp a)
a - number from which arc-tangent is desiredpublic static Dfp asin(Dfp a)
a - number from which arc-sine is desiredCopyright © 2003–2017 The Apache Software Foundation. All rights reserved.