Package org.hipparchus.util
Class BigReal
java.lang.Object
org.hipparchus.util.BigReal
- All Implemented Interfaces:
Serializable
,Comparable<BigReal>
,FieldElement<BigReal>
public class BigReal
extends Object
implements FieldElement<BigReal>, Comparable<BigReal>, Serializable
Arbitrary precision decimal number.
This class is a simple wrapper around the standard BigDecimal
in order to implement the FieldElement
interface.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionBigReal
(char[] in) Build an instance from a characters representation.BigReal
(char[] in, int offset, int len) Build an instance from a characters representation.BigReal
(char[] in, int offset, int len, MathContext mc) Build an instance from a characters representation.BigReal
(char[] in, MathContext mc) Build an instance from a characters representation.BigReal
(double val) Build an instance from a double.BigReal
(double val, MathContext mc) Build an instance from a double.BigReal
(int val) Build an instance from an int.BigReal
(int val, MathContext mc) Build an instance from an int.BigReal
(long val) Build an instance from a long.BigReal
(long val, MathContext mc) Build an instance from a long.Build an instance from a String representation.BigReal
(String val, MathContext mc) Build an instance from a String representation.BigReal
(BigDecimal val) Build an instance from a BigDecimal.BigReal
(BigInteger val) Build an instance from a BigInteger.BigReal
(BigInteger unscaledVal, int scale) Build an instance from an unscaled BigInteger.BigReal
(BigInteger unscaledVal, int scale, MathContext mc) Build an instance from an unscaled BigInteger.BigReal
(BigInteger val, MathContext mc) Build an instance from a BigInteger. -
Method Summary
Modifier and TypeMethodDescriptionCompute this + a.Get the BigDecimal value corresponding to the instance.int
Compute this ÷ a.double
Get the double value corresponding to the instance.boolean
getField()
Get theField
to which the instance belongs.double
getReal()
Get the real value of the number.Gets the rounding mode for division operations The default isRoundingMode.HALF_UP
int
getScale()
Sets the scale for division operations.int
hashCode()
multiply
(int n) Compute n × this.Compute this × a.negate()
Returns the additive inverse ofthis
element.Returns the multiplicative inverse ofthis
element.void
setRoundingMode
(RoundingMode roundingMode) Sets the rounding mode for decimal divisions.void
setScale
(int scale) Sets the scale for division operations.Compute this - a.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hipparchus.FieldElement
isZero
-
Field Details
-
ZERO
A big real representing 0. -
ONE
A big real representing 1.
-
-
Constructor Details
-
BigReal
Build an instance from a BigDecimal.- Parameters:
val
- value of the instance
-
BigReal
Build an instance from a BigInteger.- Parameters:
val
- value of the instance
-
BigReal
Build an instance from an unscaled BigInteger.- Parameters:
unscaledVal
- unscaled valuescale
- scale to use
-
BigReal
Build an instance from an unscaled BigInteger.- Parameters:
unscaledVal
- unscaled valuescale
- scale to usemc
- to used
-
BigReal
Build an instance from a BigInteger.- Parameters:
val
- value of the instancemc
- context to use
-
BigReal
public BigReal(char[] in) Build an instance from a characters representation.- Parameters:
in
- character representation of the value
-
BigReal
public BigReal(char[] in, int offset, int len) Build an instance from a characters representation.- Parameters:
in
- character representation of the valueoffset
- offset of the first character to analyzelen
- length of the array slice to analyze
-
BigReal
Build an instance from a characters representation.- Parameters:
in
- character representation of the valueoffset
- offset of the first character to analyzelen
- length of the array slice to analyzemc
- context to use
-
BigReal
Build an instance from a characters representation.- Parameters:
in
- character representation of the valuemc
- context to use
-
BigReal
public BigReal(double val) Build an instance from a double.- Parameters:
val
- value of the instance
-
BigReal
Build an instance from a double.- Parameters:
val
- value of the instancemc
- context to use
-
BigReal
public BigReal(int val) Build an instance from an int.- Parameters:
val
- value of the instance
-
BigReal
Build an instance from an int.- Parameters:
val
- value of the instancemc
- context to use
-
BigReal
public BigReal(long val) Build an instance from a long.- Parameters:
val
- value of the instance
-
BigReal
Build an instance from a long.- Parameters:
val
- value of the instancemc
- context to use
-
BigReal
Build an instance from a String representation.- Parameters:
val
- character representation of the value
-
BigReal
Build an instance from a String representation.- Parameters:
val
- character representation of the valuemc
- context to use
-
-
Method Details
-
getReal
public double getReal()Get the real value of the number.- Specified by:
getReal
in interfaceFieldElement<BigReal>
- Returns:
- real value
-
getRoundingMode
Gets the rounding mode for division operations The default isRoundingMode.HALF_UP
- Returns:
- the rounding mode.
-
setRoundingMode
Sets the rounding mode for decimal divisions.- Parameters:
roundingMode
- rounding mode for decimal divisions
-
getScale
public int getScale()Sets the scale for division operations. The default is 64- Returns:
- the scale
-
setScale
public void setScale(int scale) Sets the scale for division operations.- Parameters:
scale
- scale for division operations
-
add
Compute this + a.- Specified by:
add
in interfaceFieldElement<BigReal>
- Parameters:
a
- element to add- Returns:
- a new element representing this + a
-
subtract
Compute this - a.- Specified by:
subtract
in interfaceFieldElement<BigReal>
- Parameters:
a
- element to subtract- Returns:
- a new element representing this - a
-
negate
Returns the additive inverse ofthis
element.- Specified by:
negate
in interfaceFieldElement<BigReal>
- Returns:
- the opposite of
this
.
-
divide
Compute this ÷ a.- Specified by:
divide
in interfaceFieldElement<BigReal>
- Parameters:
a
- element to divide by- Returns:
- a new element representing this ÷ a
- Throws:
MathRuntimeException
- ifa
is zero
-
reciprocal
Returns the multiplicative inverse ofthis
element.- Specified by:
reciprocal
in interfaceFieldElement<BigReal>
- Returns:
- the inverse of
this
. - Throws:
MathRuntimeException
- ifthis
is zero
-
multiply
Compute this × a.- Specified by:
multiply
in interfaceFieldElement<BigReal>
- Parameters:
a
- element to multiply- Returns:
- a new element representing this × a
-
multiply
Compute n × this. Multiplication by an integer number is defined as the following sum \[ n \times \mathrm{this} = \sum_{i=1}^n \mathrm{this} \]- Specified by:
multiply
in interfaceFieldElement<BigReal>
- Parameters:
n
- Number of timesthis
must be added to itself.- Returns:
- A new element representing n × this.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<BigReal>
-
doubleValue
public double doubleValue()Get the double value corresponding to the instance.- Returns:
- double value corresponding to the instance
-
bigDecimalValue
Get the BigDecimal value corresponding to the instance.- Returns:
- BigDecimal value corresponding to the instance
-
equals
-
hashCode
public int hashCode() -
getField
Get theField
to which the instance belongs.- Specified by:
getField
in interfaceFieldElement<BigReal>
- Returns:
Field
to which the instance belongs
-