| Modifier and Type | Class | Description |
|---|---|---|
static class |
DfpField.RoundingMode |
Enumerate for rounding modes.
|
| Modifier and Type | Field | Description |
|---|---|---|
static int |
FLAG_DIV_ZERO |
IEEE 854-1987 flag for division by zero.
|
static int |
FLAG_INEXACT |
IEEE 854-1987 flag for inexact result.
|
static int |
FLAG_INVALID |
IEEE 854-1987 flag for invalid operation.
|
static int |
FLAG_OVERFLOW |
IEEE 854-1987 flag for overflow.
|
static int |
FLAG_UNDERFLOW |
IEEE 854-1987 flag for underflow.
|
| Constructor | Description |
|---|---|
DfpField(int decimalDigits) |
Create a factory for the specified number of radix digits.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
clearIEEEFlags() |
Clears the IEEE 854 status flags.
|
static Dfp |
computeExp(Dfp a,
Dfp one) |
Compute exp(a).
|
static Dfp |
computeLn(Dfp a,
Dfp one,
Dfp two) |
Compute ln(a).
|
Dfp |
getE() |
Get the constant e.
|
Dfp[] |
getESplit() |
Get the constant e split in two pieces.
|
int |
getIEEEFlags() |
Get the IEEE 854 status flags.
|
Dfp |
getLn10() |
Get the constant ln(10).
|
Dfp |
getLn2() |
Get the constant ln(2).
|
Dfp[] |
getLn2Split() |
Get the constant ln(2) split in two pieces.
|
Dfp |
getLn5() |
Get the constant ln(5).
|
Dfp[] |
getLn5Split() |
Get the constant ln(5) split in two pieces.
|
Dfp |
getOne() |
Get the constant 1.
|
Dfp |
getPi() |
Get the constant π.
|
Dfp[] |
getPiSplit() |
Get the constant π split in two pieces.
|
int |
getRadixDigits() |
Get the number of radix digits of the
Dfp instances built by this factory. |
DfpField.RoundingMode |
getRoundingMode() |
Get the current rounding mode.
|
Class<? extends FieldElement<Dfp>> |
getRuntimeClass() |
Returns the runtime class of the FieldElement.
|
Dfp |
getSqr2() |
Get the constant √2.
|
Dfp |
getSqr2Reciprocal() |
Get the constant √2 / 2.
|
Dfp[] |
getSqr2Split() |
Get the constant √2 split in two pieces.
|
Dfp |
getSqr3() |
Get the constant √3.
|
Dfp |
getSqr3Reciprocal() |
Get the constant √3 / 3.
|
Dfp |
getTwo() |
Get the constant 2.
|
Dfp |
getZero() |
Get the constant 0.
|
Dfp |
newDfp() |
Makes a
Dfp with a value of 0. |
Dfp |
newDfp(byte x) |
Create an instance from a byte value.
|
Dfp |
newDfp(byte sign,
byte nans) |
Creates a
Dfp with a non-finite value. |
Dfp |
newDfp(double x) |
Create an instance from a double value.
|
Dfp |
newDfp(int x) |
Create an instance from an int value.
|
Dfp |
newDfp(long x) |
Create an instance from a long value.
|
Dfp |
newDfp(String s) |
Create a
Dfp given a String representation. |
Dfp |
newDfp(Dfp d) |
Copy constructor.
|
void |
setIEEEFlags(int flags) |
Sets the IEEE 854 status flags.
|
void |
setIEEEFlagsBits(int bits) |
Sets some bits in the IEEE 854 status flags, without changing the already set bits.
|
void |
setRoundingMode(DfpField.RoundingMode mode) |
Set the rounding mode.
|
public static final int FLAG_INVALID
public static final int FLAG_DIV_ZERO
public static final int FLAG_OVERFLOW
public static final int FLAG_UNDERFLOW
public static final int FLAG_INEXACT
public DfpField(int decimalDigits)
Note that since the Dfp class uses 10000 as its radix, each radix
digit is equivalent to 4 decimal digits. This implies that asking for
13, 14, 15 or 16 decimal digits will really lead to a 4 radix 10000 digits in
all cases.
decimalDigits - minimal number of decimal digits.public int getRadixDigits()
Dfp instances built by this factory.public void setRoundingMode(DfpField.RoundingMode mode)
DfpField.RoundingMode.ROUND_HALF_EVEN.public DfpField.RoundingMode getRoundingMode()
public int getIEEEFlags()
clearIEEEFlags(),
setIEEEFlags(int),
setIEEEFlagsBits(int),
FLAG_INVALID,
FLAG_DIV_ZERO,
FLAG_OVERFLOW,
FLAG_UNDERFLOW,
FLAG_INEXACTpublic void clearIEEEFlags()
public void setIEEEFlags(int flags)
flags - desired value for the flagsgetIEEEFlags(),
clearIEEEFlags(),
setIEEEFlagsBits(int),
FLAG_INVALID,
FLAG_DIV_ZERO,
FLAG_OVERFLOW,
FLAG_UNDERFLOW,
FLAG_INEXACTpublic void setIEEEFlagsBits(int bits)
Calling this method is equivalent to call setIEEEFlags(getIEEEFlags() | bits)
bits - bits to setgetIEEEFlags(),
clearIEEEFlags(),
setIEEEFlags(int),
FLAG_INVALID,
FLAG_DIV_ZERO,
FLAG_OVERFLOW,
FLAG_UNDERFLOW,
FLAG_INEXACTpublic Dfp newDfp(byte x)
x - value to convert to an instanceDfp with the same value as xpublic Dfp newDfp(int x)
x - value to convert to an instanceDfp with the same value as xpublic Dfp newDfp(long x)
x - value to convert to an instanceDfp with the same value as xpublic Dfp newDfp(double x)
x - value to convert to an instanceDfp with the same value as xpublic Dfp newDfp(Dfp d)
d - instance to copyDfp with the same value as dpublic Dfp newDfp(String s)
Dfp given a String representation.s - string representation of the instanceDfp parsed from specified stringpublic Dfp newDfp(byte sign, byte nans)
Dfp with a non-finite value.sign - sign of the Dfp to createnans - code of the value, must be one of Dfp.INFINITE,
Dfp.SNAN, Dfp.QNANDfp with a non-finite valuepublic Dfp getZero()
public Dfp getOne()
public Class<? extends FieldElement<Dfp>> getRuntimeClass()
getRuntimeClass in interface Field<Dfp>Class object that represents the runtime
class of this object.public Dfp[] getSqr2Split()
Dfp with value √2 split in two piecespublic Dfp getSqr2Reciprocal()
Dfp with value √2 / 2public Dfp getSqr3Reciprocal()
Dfp with value √3 / 3public Dfp[] getPiSplit()
Dfp with value π split in two piecespublic Dfp[] getESplit()
Dfp with value e split in two piecespublic Dfp[] getLn2Split()
Dfp with value ln(2) split in two piecespublic Dfp[] getLn5Split()
Dfp with value ln(5) split in two piecespublic static Dfp computeExp(Dfp a, Dfp one)
a - number for which we want the exponentialone - constant with value 1 at desired precisionpublic static Dfp computeLn(Dfp a, Dfp one, Dfp two)
Let f(x) = ln(x),
We know that f'(x) = 1/x, thus from Taylor's theorem 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 for which we want the exponentialone - constant with value 1 at desired precisiontwo - constant with value 2 at desired precisionCopyright © 2003–2017 The Apache Software Foundation. All rights reserved.