Package org.hipparchus.dfp
Class DfpField
java.lang.Object
org.hipparchus.dfp.DfpField
Field for Decimal floating point instances.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIEEE 854-1987 flag for division by zero.static final intIEEE 854-1987 flag for inexact result.static final intIEEE 854-1987 flag for invalid operation.static final intIEEE 854-1987 flag for overflow.static final intIEEE 854-1987 flag for underflow. -
Constructor Summary
ConstructorsConstructorDescriptionDfpField(int decimalDigits) Create a factory for the specified number of radix digits. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the IEEE 854 status flags.static DfpcomputeExp(Dfp a, Dfp one) Compute exp(a).static DfpCompute ln(a).booleanGet the degrees to radians conversion factor.getE()Get the constant e.Dfp[]Get the constant e split in two pieces.getExtendedField(int digitsFactor, boolean computeConstants) Get extended field for accuracy conversion.intGet the IEEE 854 status flags.getLn10()Get the constant ln(10).getLn2()Get the constant ln(2).Dfp[]Get the constant ln(2) split in two pieces.getLn5()Get the constant ln(5).Dfp[]Get the constant ln(5) split in two pieces.getOne()Get the constant 1.getPi()Get the constant π.Dfp[]Get the constant π split in two pieces.intGet the number of radix digits of theDfpinstances built by this factory.Get the radians to degrees conversion factor.Get the current rounding mode.Returns the runtime class of the FieldElement.getSqr2()Get the constant √2.Get the constant √2 / 2.Dfp[]Get the constant √2 split in two pieces.getSqr3()Get the constant √3.Get the constant √3 / 3.getTwo()Get the constant 2.getZero()Get the constant 0.inthashCode()newDfp()Makes aDfpwith a value of 0.newDfp(byte x) Create an instance from a byte value.newDfp(byte sign, byte nans) Creates aDfpwith a non-finite value.newDfp(double x) Create an instance from a double value.newDfp(int x) Create an instance from an int value.newDfp(long x) Create an instance from a long value.Create aDfpgiven a String representation.Copy constructor.voidsetIEEEFlags(int flags) Sets the IEEE 854 status flags.voidsetIEEEFlagsBits(int bits) Sets some bits in the IEEE 854 status flags, without changing the already set bits.voidSet the rounding mode.
-
Field Details
-
FLAG_INVALID
public static final int FLAG_INVALIDIEEE 854-1987 flag for invalid operation.- See Also:
-
FLAG_DIV_ZERO
public static final int FLAG_DIV_ZEROIEEE 854-1987 flag for division by zero.- See Also:
-
FLAG_OVERFLOW
public static final int FLAG_OVERFLOWIEEE 854-1987 flag for overflow.- See Also:
-
FLAG_UNDERFLOW
public static final int FLAG_UNDERFLOWIEEE 854-1987 flag for underflow.- See Also:
-
FLAG_INEXACT
public static final int FLAG_INEXACTIEEE 854-1987 flag for inexact result.- See Also:
-
-
Constructor Details
-
DfpField
public DfpField(int decimalDigits) Create a factory for the specified number of radix digits.Note that since the
Dfpclass 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.- Parameters:
decimalDigits- minimal number of decimal digits.
-
-
Method Details
-
getRadixDigits
public int getRadixDigits()Get the number of radix digits of theDfpinstances built by this factory.- Returns:
- number of radix digits
-
setRoundingMode
Set the rounding mode. If not set, the default value isDfpField.RoundingMode.ROUND_HALF_EVEN. -
getRoundingMode
Get the current rounding mode.- Returns:
- current rounding mode
-
getIEEEFlags
public int getIEEEFlags()Get the IEEE 854 status flags.- Returns:
- IEEE 854 status flags
- See Also:
-
clearIEEEFlags
public void clearIEEEFlags()Clears the IEEE 854 status flags.- See Also:
-
setIEEEFlags
public void setIEEEFlags(int flags) Sets the IEEE 854 status flags.- Parameters:
flags- desired value for the flags- See Also:
-
setIEEEFlagsBits
public void setIEEEFlagsBits(int bits) Sets some bits in the IEEE 854 status flags, without changing the already set bits.Calling this method is equivalent to call
setIEEEFlags(getIEEEFlags() | bits)- Parameters:
bits- bits to set- See Also:
-
newDfp
Makes aDfpwith a value of 0.- Returns:
- a new
Dfpwith a value of 0
-
newDfp
Create an instance from a byte value.- Parameters:
x- value to convert to an instance- Returns:
- a new
Dfpwith the same value as x
-
newDfp
Create an instance from an int value.- Parameters:
x- value to convert to an instance- Returns:
- a new
Dfpwith the same value as x
-
newDfp
Create an instance from a long value.- Parameters:
x- value to convert to an instance- Returns:
- a new
Dfpwith the same value as x
-
newDfp
Create an instance from a double value.- Parameters:
x- value to convert to an instance- Returns:
- a new
Dfpwith the same value as x
-
newDfp
Copy constructor.- Parameters:
d- instance to copy- Returns:
- a new
Dfpwith the same value as d
-
newDfp
Create aDfpgiven a String representation.- Parameters:
s- string representation of the instance- Returns:
- a new
Dfpparsed from specified string
-
newDfp
Creates aDfpwith a non-finite value.- Parameters:
sign- sign of the Dfp to createnans- code of the value, must be one ofDfp.INFINITE,Dfp.SNAN,Dfp.QNAN- Returns:
- a new
Dfpwith a non-finite value
-
getZero
Get the constant 0. -
getOne
Get the constant 1. -
getRuntimeClass
Returns the runtime class of the FieldElement.- Specified by:
getRuntimeClassin interfaceField<Dfp>- Returns:
- The
Classobject that represents the runtime class of this object.
-
getTwo
Get the constant 2.- Returns:
- a
Dfpwith value 2
-
getSqr2
Get the constant √2.- Returns:
- a
Dfpwith value √2
-
getSqr2Split
Get the constant √2 split in two pieces.- Returns:
- a
Dfpwith value √2 split in two pieces
-
getSqr2Reciprocal
Get the constant √2 / 2.- Returns:
- a
Dfpwith value √2 / 2
-
getSqr3
Get the constant √3.- Returns:
- a
Dfpwith value √3
-
getSqr3Reciprocal
Get the constant √3 / 3.- Returns:
- a
Dfpwith value √3 / 3
-
getPi
Get the constant π.- Returns:
- a
Dfpwith value π
-
getDegToRad
Get the degrees to radians conversion factor.- Returns:
- a
Dfpfor degrees to radians conversion factor
-
getRadToDeg
Get the radians to degrees conversion factor.- Returns:
- a
Dfpfor radians to degrees conversion factor
-
getPiSplit
Get the constant π split in two pieces.- Returns:
- a
Dfpwith value π split in two pieces
-
getE
Get the constant e.- Returns:
- a
Dfpwith value e
-
getESplit
Get the constant e split in two pieces.- Returns:
- a
Dfpwith value e split in two pieces
-
getLn2
Get the constant ln(2).- Returns:
- a
Dfpwith value ln(2)
-
getLn2Split
Get the constant ln(2) split in two pieces.- Returns:
- a
Dfpwith value ln(2) split in two pieces
-
getLn5
Get the constant ln(5).- Returns:
- a
Dfpwith value ln(5)
-
getLn5Split
Get the constant ln(5) split in two pieces.- Returns:
- a
Dfpwith value ln(5) split in two pieces
-
getLn10
Get the constant ln(10).- Returns:
- a
Dfpwith value ln(10)
-
equals
Two fields are considered equals if they have the same number of radix digits and the same rounding mode.
-
hashCode
public int hashCode() -
computeExp
Compute exp(a).- Parameters:
a- number for which we want the exponentialone- constant with value 1 at desired precision- Returns:
- exp(a)
-
computeLn
Compute ln(a). 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).- Parameters:
a- number for which we want the exponentialone- constant with value 1 at desired precisiontwo- constant with value 2 at desired precision- Returns:
- ln(a)
-
getExtendedField
Get extended field for accuracy conversion.- Parameters:
digitsFactor- multiplication factor for number of digitscomputeConstants- if true, the transcendental constants for the given precision must be computed (setting this flag to false is RESERVED for the internal recursive call)- Returns:
- field with extended precision
- Since:
- 1.7
-