Package org.teavm.classlib.java.math
Class TMathContext
java.lang.Object
org.teavm.classlib.java.math.TMathContext
- All Implemented Interfaces:
Serializable
Immutable objects describing settings such as rounding mode and digit
precision for the numerical operations provided by class
TBigDecimal
.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TMathContext
AMathContext
which corresponds to the IEEE 754r quadruple decimal precision format: 34 digit precision andTRoundingMode.HALF_EVEN
rounding.static final TMathContext
AMathContext
which corresponds to the IEEE 754r single decimal precision format: 7 digit precision andTRoundingMode.HALF_EVEN
rounding.static final TMathContext
AMathContext
which corresponds to the IEEE 754r double decimal precision format: 16 digit precision andTRoundingMode.HALF_EVEN
rounding.static final TMathContext
AMathContext
for unlimited precision withTRoundingMode.HALF_UP
rounding. -
Constructor Summary
ConstructorsConstructorDescriptionTMathContext
(int precision) Constructs a newMathContext
with the specified precision and with the rounding modeHALF_UP
.TMathContext
(int precision, TRoundingMode roundingMode) Constructs a newMathContext
with the specified precision and with the specified rounding mode.TMathContext
(String val) Constructs a newMathContext
from a string. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if x is aMathContext
with the same precision setting and the same rounding mode as thisMathContext
instance.int
Returns the precision.Returns the rounding mode.int
hashCode()
Returns the hash code for thisMathContext
instance.toString()
Returns the string representation for thisMathContext
instance.
-
Field Details
-
DECIMAL128
AMathContext
which corresponds to the IEEE 754r quadruple decimal precision format: 34 digit precision andTRoundingMode.HALF_EVEN
rounding. -
DECIMAL32
AMathContext
which corresponds to the IEEE 754r single decimal precision format: 7 digit precision andTRoundingMode.HALF_EVEN
rounding. -
DECIMAL64
AMathContext
which corresponds to the IEEE 754r double decimal precision format: 16 digit precision andTRoundingMode.HALF_EVEN
rounding. -
UNLIMITED
AMathContext
for unlimited precision withTRoundingMode.HALF_UP
rounding.
-
-
Constructor Details
-
TMathContext
public TMathContext(int precision) Constructs a newMathContext
with the specified precision and with the rounding modeHALF_UP
. If the precision passed is zero, then this implies that the computations have to be performed exact, the rounding mode in this case is irrelevant.- Parameters:
precision
- the precision for the newMathContext
.- Throws:
IllegalArgumentException
- ifprecision < 0
.
-
TMathContext
Constructs a newMathContext
with the specified precision and with the specified rounding mode. If the precision passed is zero, then this implies that the computations have to be performed exact, the rounding mode in this case is irrelevant.- Parameters:
precision
- the precision for the newMathContext
.roundingMode
- the rounding mode for the newMathContext
.- Throws:
IllegalArgumentException
- ifprecision < 0
.NullPointerException
- ifroundingMode
isnull
.
-
TMathContext
Constructs a newMathContext
from a string. The string has to specify the precision and the rounding mode to be used and has to follow the following syntax: "precision=<precision> roundingMode=<roundingMode>" This is the same form as the one returned by thetoString()
method.- Parameters:
val
- a string describing the precision and rounding mode for the newMathContext
.- Throws:
IllegalArgumentException
- if the string is not in the correct format or if the precision specified is < 0.
-
-
Method Details
-
getPrecision
public int getPrecision()Returns the precision. The precision is the number of digits used for an operation. Results are rounded to this precision. The precision is guaranteed to be non negative. If the precision is zero, then the computations have to be performed exact, results are not rounded in this case.- Returns:
- the precision.
-
getRoundingMode
Returns the rounding mode. The rounding mode is the strategy to be used to round results.The rounding mode is one of
TRoundingMode.UP
,TRoundingMode.DOWN
,TRoundingMode.CEILING
,TRoundingMode.FLOOR
,TRoundingMode.HALF_UP
,TRoundingMode.HALF_DOWN
,TRoundingMode.HALF_EVEN
, orTRoundingMode.UNNECESSARY
.- Returns:
- the rounding mode.
-
equals
Returns true if x is aMathContext
with the same precision setting and the same rounding mode as thisMathContext
instance. -
hashCode
public int hashCode()Returns the hash code for thisMathContext
instance. -
toString
Returns the string representation for thisMathContext
instance. The string has the form"precision=<precision> roundingMode=<roundingMode>"
where<precision>
is an integer describing the number of digits used for operations and<roundingMode>
is the string representation of the rounding mode.
-