public final class EContext extends Object
Thread
safety: With one exception, instances of this class are immutable
and are safe to use among multiple threads. The one exception
involves the Flags property. If the context's HasFlags
property (a read-only property) is true, the Flags
property is mutable, thus making the context mutable. This class
doesn't synchronize access to such mutable contexts, so applications
should provide their own synchronization if a context with the
HasFlags property set to true will be shared among
multiple threads and at least one of those threads needs to write the
Flags property (which can happen, for example, by passing the
context to most methods of EDecimal such as Add).
| Modifier and Type | Field and Description |
|---|---|
static EContext |
Basic
A basic arithmetic context, 9 digits precision, rounding mode half-up,
unlimited exponent range.
|
static EContext |
BigDecimalJava
An arithmetic context for Java's BigDecimal format.
|
static EContext |
Binary128
An arithmetic context for the IEEE-754-2008 binary128 format, 113 bits
precision.
|
static EContext |
Binary16
An arithmetic context for the IEEE-754-2008 binary16 format, 11 bits
precision.
|
static EContext |
Binary32
An arithmetic context for the IEEE-754-2008 binary32 format, 24 bits
precision.
|
static EContext |
Binary64
An arithmetic context for the IEEE-754-2008 binary64 format, 53 bits
precision.
|
static EContext |
CliDecimal
An arithmetic context for the .NET Framework decimal format (see
"Forms of numbers"), 96 bits
precision, and a valid exponent range of -28 to 0. |
static EContext |
Decimal128
An arithmetic context for the IEEE-754-2008 decimal128 format.
|
static EContext |
Decimal32
An arithmetic context for the IEEE-754-2008 decimal32 format.
|
static EContext |
Decimal64
An arithmetic context for the IEEE-754-2008 decimal64 format.
|
static int |
FlagClamped
Signals that the exponent was adjusted to fit the exponent range.
|
static int |
FlagDivideByZero
Signals a division of a nonzero number by zero.
|
static int |
FlagInexact
Signals that the result was rounded to a different mathematical value, but
as close as possible to the original.
|
static int |
FlagInvalid
Signals an invalid operation.
|
static int |
FlagLostDigits
Signals that an operand was rounded to a different mathematical value before
an operation.
|
static int |
FlagOverflow
Signals that the result is non-zero and the exponent is higher than the
highest exponent allowed.
|
static int |
FlagRounded
Signals that the result was rounded to fit the precision; either the value
or the exponent may have changed from the original.
|
static int |
FlagSubnormal
Signals that the result's exponent, before rounding, is lower than the
lowest exponent allowed.
|
static int |
FlagUnderflow
Signals that the result's exponent, before rounding, is lower than the
lowest exponent allowed, and the result was rounded to a different
mathematical value, but as close as possible to the original.
|
static EContext |
Unlimited
No specific (theoretical) limit on precision.
|
static EContext |
UnlimitedHalfEven
No specific (theoretical) limit on precision.
|
| Constructor and Description |
|---|
EContext(int precision,
ERounding rounding,
int exponentMinSmall,
int exponentMaxSmall,
boolean clampNormalExponents)
Initializes a new instance of the
EContext
class. |
| Modifier and Type | Method and Description |
|---|---|
EContext |
Copy()
Initializes a new EContext that is a copy of another EContext.
|
boolean |
ExponentWithinRange(EInteger exponent)
Determines whether a number can have the given Exponent property under this
arithmetic context.
|
static EContext |
ForPrecision(int precision)
Creates a new arithmetic context using the given maximum number of digits,
an unlimited exponent range, and the HalfUp rounding mode.
|
static EContext |
ForPrecisionAndRounding(int precision,
ERounding rounding)
Creates a new EContext object initialized with an unlimited exponent range,
and the given rounding mode and maximum precision.
|
static EContext |
ForRounding(ERounding rounding)
Creates a new EContext object initialized with an unlimited precision, an
unlimited exponent range, and the given rounding mode.
|
boolean |
getAdjustExponent()
Gets a value indicating whether the EMax and EMin properties refer to the
number's Exponent property adjusted to the number's precision, or
just the number's Exponent property.
|
boolean |
getClampNormalExponents()
Gets a value indicating whether a converted number's Exponent property
will not be higher than EMax + 1 - Precision.
|
EInteger |
getEMax()
Gets the highest exponent possible when a converted number is expressed in
scientific notation with one digit before the radix point.
|
EInteger |
getEMin()
Gets the lowest exponent possible when a converted number is expressed in
scientific notation with one digit before the radix point.
|
int |
getFlags()
Gets the flags that are set from converting numbers according to this
arithmetic context.
|
boolean |
getHasExponentRange()
Gets a value indicating whether this context defines a minimum and maximum
exponent.
|
boolean |
getHasFlags()
Gets a value indicating whether this context has a mutable Flags field.
|
boolean |
getHasMaxPrecision()
Gets a value indicating whether this context defines a maximum precision.
|
EInteger |
getPrecision()
Gets the maximum length of a converted number in digits, ignoring the radix
point and exponent.
|
ERounding |
getRounding()
Gets the desired rounding mode when converting numbers that can't be
represented in the given precision and exponent range.
|
int |
getTraps()
Gets the traps that are set for each flag in the context.
|
boolean |
isPrecisionInBits()
Gets a value indicating whether this context's Precision property is in
bits, rather than digits.
|
boolean |
isSimplified()
Gets a value indicating whether to use a "simplified" arithmetic.
|
void |
setFlags(int value) |
String |
toString()
Gets a string representation of this object.
|
EContext |
WithAdjustExponent(boolean adjustExponent)
Copies this EContext and sets the copy's "AdjustExponent" property to the
given value.
|
EContext |
WithBigExponentRange(EInteger exponentMin,
EInteger exponentMax)
Copies this arithmetic context and sets the copy's exponent range.
|
EContext |
WithBigPrecision(EInteger bigintPrecision)
Copies this EContext and gives it a particular precision value.
|
EContext |
WithBlankFlags()
Copies this EContext with
HasFlags set to true and a Flags value of
0. |
EContext |
WithExponentClamp(boolean clamp)
Copies this arithmetic context and sets the copy's "ClampNormalExponents"
flag to the given value.
|
EContext |
WithExponentRange(int exponentMinSmall,
int exponentMaxSmall)
Copies this arithmetic context and sets the copy's exponent range.
|
EContext |
WithNoFlags()
Copies this EContext with
HasFlags set to false and a Flags value of
0. |
EContext |
WithPrecision(int precision)
Copies this EContext and gives it a particular precision value.
|
EContext |
WithPrecisionInBits(boolean isPrecisionBits)
Copies this EContext and sets the copy's "IsPrecisionInBits" property to the
given value.
|
EContext |
WithRounding(ERounding rounding)
Copies this EContext with the specified rounding mode.
|
EContext |
WithSimplified(boolean simplified)
Copies this EContext and sets the copy's "IsSimplified" property to the
given value.
|
EContext |
WithTraps(int traps)
Copies this EContext with Traps set to the given value.
|
EContext |
WithUnlimitedExponents()
Copies this EContext with an unlimited exponent range.
|
public static final int FlagClamped
public static final int FlagDivideByZero
public static final int FlagInexact
public static final int FlagInvalid
public static final int FlagLostDigits
public static final int FlagOverflow
public static final int FlagRounded
public static final int FlagSubnormal
public static final int FlagUnderflow
public static final EContext Basic
public static final EContext BigDecimalJava
public static final EContext Binary128
public static final EContext Binary16
public static final EContext Binary32
public static final EContext Binary64
public static final EContext CliDecimal
"Forms of numbers"), 96 bits
precision, and a valid exponent range of -28 to 0. The default
rounding mode is HalfEven. (The "Cli" stands for "Common
Language Infrastructure", which defined this format as the .NET
Framework decimal format in version 1, but leaves it unspecified in
later versions.).public static final EContext Decimal128
public static final EContext Decimal32
public static final EContext Decimal64
public static final EContext Unlimited
public static final EContext UnlimitedHalfEven
public EContext(int precision,
ERounding rounding,
int exponentMinSmall,
int exponentMaxSmall,
boolean clampNormalExponents)
EContext
class. HasFlags will be set to false.precision - The maximum number of digits a number can have, or 0 for an
unlimited number of digits.rounding - The rounding mode to use when a number can't fit the given
precision.exponentMinSmall - The minimum exponent.exponentMaxSmall - The maximum exponent.clampNormalExponents - Whether to clamp a number's significand to the
given maximum precision (if it isn't zero) while remaining within the
exponent range.public final boolean getAdjustExponent()
true if the EMax and EMin properties refer to the number's
Exponent property adjusted to the number's precision, or false if
they refer to just the number's Exponent property.public final boolean getClampNormalExponents()
public final EInteger getEMax()
public final EInteger getEMin()
public final int getFlags()
HasFlags is false, this value will be
0. This value is a combination of bit fields. To retrieve a
particular flag, use the AND operation on the return value of this
method. For example: (this.getFlags() & EContext.FlagInexact) !=
0 returns true if the Inexact flag is set.HasFlags is false, this value will be
0.public final void setFlags(int value)
public final boolean getHasExponentRange()
true if this context defines a minimum and maximum exponent;
otherwise, false.public final boolean getHasFlags()
true if this context has a mutable Flags field; otherwise,
false.public final boolean getHasMaxPrecision()
true if this context defines a maximum precision; otherwise,
false.public final boolean isPrecisionInBits()
true if this context's Precision property is in bits, rather
than digits; otherwise, false. The default is false.public final boolean isSimplified()
http://speleotrove.com/decimal/dax3274.htmltrue if a "simplified" arithmetic will be used; otherwise,
false.public final EInteger getPrecision()
public final ERounding getRounding()
public final int getTraps()
HasFlags is false, and the flag's trap is
enabled, the operation will throw a TrapException. For example, if
Traps equals FlagInexact and FlagSubnormal, a TrapException
will be thrown if an operation's return value is not the same as the
exact result (FlagInexact) or if the return value's exponent is lower
than the lowest allowed (FlagSubnormal).
public static EContext ForPrecision(int precision)
precision - Maximum number of digits (precision).public static EContext ForPrecisionAndRounding(int precision, ERounding rounding)
precision - Maximum number of digits (precision).rounding - An ERounding object.public static EContext ForRounding(ERounding rounding)
rounding - The rounding mode for the new precision context.public EContext Copy()
public boolean ExponentWithinRange(EInteger exponent)
exponent - An arbitrary-precision integer indicating the desired
exponent.true if a number can have the given Exponent property under
this arithmetic context; otherwise, false. If this context
allows unlimited precision, returns true for the exponent EMax and
any exponent less than EMax.NullPointerException - The parameter exponent is null.public String toString()
public EContext WithAdjustExponent(boolean adjustExponent)
adjustExponent - The new value of the "AdjustExponent" property for the
copy.public EContext WithBigExponentRange(EInteger exponentMin, EInteger exponentMax)
exponentMin - Desired minimum exponent (EMin).exponentMax - Desired maximum exponent (EMax).NullPointerException - The parameter exponentMin is
null.NullPointerException - The parameter exponentMax is
null.public EContext WithBigPrecision(EInteger bigintPrecision)
bigintPrecision - The parameter bigintPrecision is not
documented yet.NullPointerException - The parameter bigintPrecision
is null.public EContext WithBlankFlags()
HasFlags set to true and a Flags value of
0.public EContext WithExponentClamp(boolean clamp)
clamp - The parameter clamp is not documented yet.public EContext WithExponentRange(int exponentMinSmall, int exponentMaxSmall)
exponentMinSmall - Desired minimum exponent (EMin).exponentMaxSmall - Desired maximum exponent (EMax).public EContext WithNoFlags()
HasFlags set to false and a Flags value of
0.public EContext WithPrecision(int precision)
precision - Desired precision. 0 means unlimited precision.public EContext WithPrecisionInBits(boolean isPrecisionBits)
isPrecisionBits - The new value of the "IsPrecisionInBits" property for
the copy.public EContext WithRounding(ERounding rounding)
rounding - Desired value of the Rounding property.public EContext WithSimplified(boolean simplified)
simplified - The parameter simplified is not documented yet.public EContext WithTraps(int traps)
traps - Flags representing the traps to enable. See the property
"Traps".public EContext WithUnlimitedExponents()
CBOR for Java documentation, generated in 2016.