public final class EDecimal extends Object implements Comparable<EDecimal>
About decimal arithmetic
Decimal (base-10) arithmetic, such as that provided by this class, is appropriate for calculations involving such real-world data as prices and other sums of money, tax rates, and measurements. These calculations often involve multiplying or dividing one decimal with another decimal, or performing other operations on decimal numbers. Many of these calculations also rely on rounding behavior in which the result after rounding is a decimal number (for example, multiplying a price by a premium rate, then rounding, should result in a decimal amount of money).
On the other hand, most implementations of
float and double , including in C# and Java, store
numbers in a binary (base-2) floating-point format and use binary
floating-point arithmetic. Many decimal numbers can't be represented
exactly in binary floating-point format (regardless of its length).
Applying binary arithmetic to numbers intended to be decimals can
sometimes lead to unintuitive results, as is shown in the description
for the FromDouble() method of this class.
About EDecimal instances
Each instance of this class consists of an integer mantissa (significand) and an integer exponent, both arbitrary-precision. The value of the number equals mantissa (significand) * 10^exponent.
The mantissa (significand) is the value of the digits that make up a number, ignoring the decimal point and exponent. For example, in the number 2356.78, the mantissa (significand) is 235678. The exponent is where the "floating" decimal point of the number is located. A positive exponent means "move it to the right", and a negative exponent means "move it to the left." In the example 2, 356.78, the exponent is -2, since it has 2 decimal places and the decimal point is "moved to the left by 2." Therefore, in the arbitrary-precision decimal representation, this number would be stored as 235678 * 10^-2.
The mantissa (significand) and exponent format preserves trailing zeros in the number's value. This may give rise to multiple ways to store the same value. For example, 1.00 and 1 would be stored differently, even though they have the same value. In the first case, 100 * 10^-2 (100 with decimal point moved left by 2), and in the second case, 1 * 10^0 (1 with decimal point moved 0).
This class also supports values for negative zero, not-a-number (NaN) values, and infinity. Negative zero is generally used when a negative number is rounded to 0; it has the same mathematical value as positive zero. Infinity is generally used when a non-zero number is divided by zero, or when a very high or very low number can't be represented in a given exponent range. Not-a-number is generally used to signal errors.
This class implements the General Decimal Arithmetic Specification
version 1.70 (except part of chapter 6):
http://speleotrove.com/decimal/decarith.html
Errors and Exceptions
Passing a signaling NaN to any arithmetic operation shown here will signal the flag FlagInvalid and return a quiet NaN, even if another operand to that operation is a quiet NaN, unless noted otherwise.
Passing a quiet NaN to any arithmetic operation shown here will return a quiet NaN, unless noted otherwise. Invalid operations will also return a quiet NaN, as stated in the individual methods.
Unless noted otherwise, passing a null arbitrary-precision decimal argument to any method here will throw an exception.
When an arithmetic operation signals the flag FlagInvalid, FlagOverflow, or FlagDivideByZero, it will not throw an exception too, unless the flag's trap is enabled in the arithmetic context (see EContext's Traps property).
If an operation requires creating an intermediate value that might be too big to fit in memory (or might require more than 2 gigabytes of memory to store -- due to the current use of a 32-bit integer internally as a length), the operation may signal an invalid-operation flag and return not-a-number (NaN). In certain rare cases, the compareTo method may throw OutOfMemoryError (called OutOfMemoryError in Java) in the same circumstances.
Serialization
An arbitrary-precision decimal value can be serialized (converted to a stable format) in one of the following ways:
Thread safety
Instances of this class are immutable, so they are inherently safe for use by multiple threads. Multiple instances of this object with the same properties are interchangeable, so they should not be compared using the "==" operator (which might only check if each side of the operator is the same instance).
Comparison considerations
This class's natural ordering (under the compareTo method) is not consistent with the Equals method. This means that two values that compare as equal under the compareTo method might not be equal under the Equals method. The compareTo method compares the mathematical values of the two instances passed to it (and considers two different NaN values as equal), while two instances with the same mathematical value, but different exponents, will be considered unequal under the Equals method.
Forms of numbers
There are several other types of numbers that are mentioned in this class and elsewhere in this documentation. For reference, they are specified here.
Unsigned integer : An integer that's always 0 or greater, with the following maximum values:
Signed integer : An integer in two's complement form , with the following ranges:
Two's complement form : In two' s-complement form , positive numbers have the highest (most significant) bit set to zero, and negative numbers have that bit (and all bits beyond) set to one. To store a negative number, decrease its absolute value by 1 and swap the bits of the resulting number.
64-bit floating-point number : A 64-bit binary floating-point number, in the form significand * 2 exponent . The significand is 53 bits long (Precision) and the exponent ranges from -1074 (EMin) to 971 (EMax). The number is stored in the following format (commonly called the IEEE 754 format):
|C|BBB...BBB|AAAAAA...AAAAAA| The elements described above are in the same order as the order of each bit of each element, that is, either most significant first or least significant first.
32-bit floating-point number : A 32-bit binary number which is stored similarly to a 64-bit floating-point number , except that:
.NET Framework decimal : A 128-bit decimal floating-point number, in the form significand * 10 - scale , where the scale ranges from 0 to 28. The number is stored in the following format:
The elements described above are in the same order as the order of each bit of each element, that is, either most significant first or least significant first.
| Modifier and Type | Field and Description |
|---|---|
static EDecimal |
NaN
A not-a-number value.
|
static EDecimal |
NegativeInfinity
Negative infinity, less than any other number.
|
static EDecimal |
NegativeZero
Represents the number negative zero.
|
static EDecimal |
One
Represents the number 1.
|
static EDecimal |
PositiveInfinity
Positive infinity, greater than any other number.
|
static EDecimal |
SignalingNaN
A not-a-number value that signals an invalid operation flag when it's
passed as an argument to any arithmetic operation in
arbitrary-precision decimal.
|
static EDecimal |
Ten
Represents the number 10.
|
static EDecimal |
Zero
Represents the number 0.
|
| Modifier and Type | Method and Description |
|---|---|
EDecimal |
Abs()
Finds the absolute value of this object (if it's negative, it becomes
positive).
|
EDecimal |
Abs(EContext context)
Finds the absolute value of this object (if it's negative, it becomes
positive).
|
EDecimal |
Add(EDecimal otherValue)
Adds this object and another decimal number and returns the result.
|
EDecimal |
Add(EDecimal otherValue,
EContext ctx)
Finds the sum of this object and another object.
|
int |
compareTo(EDecimal other)
Compares the mathematical values of this object and another object,
accepting NaN values.
|
int |
CompareToBinary(EFloat other)
Compares an arbitrary-precision binary float with this instance.
|
EDecimal |
CompareToSignal(EDecimal other,
EContext ctx)
Compares the mathematical values of this object and another object, treating
quiet NaN as signaling.
|
int |
CompareToTotal(EDecimal other)
Compares the values of this object and another object, imposing a total
ordering on all possible values.
|
int |
CompareToTotal(EDecimal other,
EContext ctx)
Compares the values of this object and another object, imposing a total
ordering on all possible values.
|
int |
CompareToTotalMagnitude(EDecimal other)
Compares the absolute values of this object and another object, imposing a
total ordering on all possible values (ignoring their signs).
|
EDecimal |
CompareToWithContext(EDecimal other,
EContext ctx)
Compares the mathematical values of this object and another object.
|
EDecimal |
CopySign(EDecimal other)
Returns a number with the same value as this one, but copying the sign
(positive or negative) of another number.
|
static EDecimal |
Create(EInteger mantissa,
EInteger exponent)
Creates a number with the value
exponent*10^mantissa |
static EDecimal |
Create(int mantissaSmall,
int exponentSmall)
Creates a number with the value
exponent*10^mantissa |
static EDecimal |
CreateNaN(EInteger diag)
Creates a not-a-number arbitrary-precision decimal number.
|
static EDecimal |
CreateNaN(EInteger diag,
boolean signaling,
boolean negative,
EContext ctx)
Creates a not-a-number arbitrary-precision decimal number.
|
EDecimal |
Divide(EDecimal divisor)
Divides this object by another decimal number and returns the result.
|
EDecimal |
Divide(EDecimal divisor,
EContext ctx)
Divides this arbitrary-precision decimal number by another
arbitrary-precision decimal number.
|
EDecimal[] |
DivideAndRemainderNaturalScale(EDecimal divisor)
Deprecated.
Renamed to DivRemNaturalScale.
|
EDecimal[] |
DivideAndRemainderNaturalScale(EDecimal divisor,
EContext ctx)
Deprecated.
Renamed to DivRemNaturalScale.
|
EDecimal |
DivideToExponent(EDecimal divisor,
EInteger exponent)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent to the result, using the half-even rounding mode.
|
EDecimal |
DivideToExponent(EDecimal divisor,
EInteger exponent,
EContext ctx)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent to the result.
|
EDecimal |
DivideToExponent(EDecimal divisor,
EInteger desiredExponent,
ERounding rounding)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent to the result.
|
EDecimal |
DivideToExponent(EDecimal divisor,
int desiredExponentInt)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent (expressed as a 32-bit signed integer) to the result, using
the half-even rounding mode.
|
EDecimal |
DivideToExponent(EDecimal divisor,
int desiredExponentInt,
EContext ctx)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent (expressed as a 32-bit signed integer) to the result, using
the half-even rounding mode.
|
EDecimal |
DivideToExponent(EDecimal divisor,
int desiredExponentInt,
ERounding rounding)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent (expressed as a 32-bit signed integer) to the result, using
the half-even rounding mode.
|
EDecimal |
DivideToExponent(EDecimal divisor,
long desiredExponentSmall)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent (expressed as a 64-bit signed integer) to the result, using
the half-even rounding mode.
|
EDecimal |
DivideToExponent(EDecimal divisor,
long desiredExponentSmall,
EContext ctx)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent to the result.
|
EDecimal |
DivideToExponent(EDecimal divisor,
long desiredExponentSmall,
ERounding rounding)
Divides two arbitrary-precision decimal numbers, and gives a particular
exponent to the result.
|
EDecimal |
DivideToIntegerNaturalScale(EDecimal divisor)
Divides two arbitrary-precision decimal numbers, and returns the integer
part of the result, rounded down, with the preferred exponent set to
this value's exponent minus the divisor's exponent.
|
EDecimal |
DivideToIntegerNaturalScale(EDecimal divisor,
EContext ctx)
Divides this object by another object, and returns the integer part of the
result (which is initially rounded down), with the preferred exponent
set to this value's exponent minus the divisor's exponent.
|
EDecimal |
DivideToIntegerZeroScale(EDecimal divisor,
EContext ctx)
Divides this object by another object, and returns the integer part of the
result, with the exponent set to 0.
|
EDecimal |
DivideToSameExponent(EDecimal divisor,
ERounding rounding)
Divides this object by another decimal number and returns a result with the
same exponent as this object (the dividend).
|
EDecimal[] |
DivRemNaturalScale(EDecimal divisor)
Calculates the quotient and remainder using the DivideToIntegerNaturalScale
and the formula in RemainderNaturalScale.
|
EDecimal[] |
DivRemNaturalScale(EDecimal divisor,
EContext ctx)
Calculates the quotient and remainder using the DivideToIntegerNaturalScale
and the formula in RemainderNaturalScale.
|
boolean |
equals(EDecimal other)
Determines whether this object's mantissa (significand), exponent, and
properties are equal to those of another object.
|
boolean |
equals(Object obj)
Determines whether this object's mantissa (significand), exponent, and
properties are equal to those of another object and that other object
is an arbitrary-precision decimal number.
|
EDecimal |
Exp(EContext ctx)
Finds e (the base of natural logarithms) raised to the power of this
object's value.
|
static EDecimal |
FromByte(byte inputByte)
Converts a byte (from 0 to 255) to an arbitrary-precision decimal number.
|
static EDecimal |
FromDouble(double dbl)
Creates a decimal number from a 64-bit binary floating-point number.
|
static EDecimal |
FromEFloat(EFloat bigfloat)
Creates a decimal number from an arbitrary-precision binary floating-point
number.
|
static EDecimal |
FromEInteger(EInteger bigint)
Converts an arbitrary-precision integer to an arbitrary precision decimal.
|
static EDecimal |
FromExtendedFloat(EFloat ef)
Deprecated.
Renamed to FromEFloat.
|
static EDecimal |
FromInt16(short inputInt16)
Converts a 16-bit signed integer to an arbitrary-precision decimal number.
|
static EDecimal |
FromInt32(int valueSmaller)
Creates a decimal number from a 32-bit signed integer.
|
static EDecimal |
FromInt64(long valueSmall)
Creates a decimal number from a 64-bit signed integer.
|
static EDecimal |
FromSingle(float flt)
Creates a decimal number from a 32-bit binary floating-point number.
|
static EDecimal |
FromString(String str)
Creates a decimal number from a text string that represents a number.
|
static EDecimal |
FromString(String str,
EContext ctx)
Creates a decimal number from a text string that represents a number.
|
static EDecimal |
FromString(String str,
int offset,
int length)
Creates a decimal number from a text string that represents a number.
|
static EDecimal |
FromString(String str,
int offset,
int length,
EContext ctx)
Creates a decimal number from a text string that represents a number.
|
EInteger |
getExponent()
Gets this object's exponent.
|
EInteger |
getMantissa()
Gets this object's unscaled value.
|
EInteger |
getUnsignedMantissa()
Gets the absolute value of this object's unscaled value.
|
int |
hashCode()
Calculates this object's hash code.
|
boolean |
isFinite()
Gets a value indicating whether this object is finite (not infinity or NaN).
|
boolean |
IsInfinity()
Gets a value indicating whether this object is positive or negative
infinity.
|
boolean |
IsNaN()
Gets a value indicating whether this object is not a number (NaN).
|
boolean |
isNegative()
Gets a value indicating whether this object is negative, including negative
zero.
|
boolean |
IsNegativeInfinity()
Returns whether this object is negative infinity.
|
boolean |
IsPositiveInfinity()
Returns whether this object is positive infinity.
|
boolean |
IsQuietNaN()
Gets a value indicating whether this object is a quiet not-a-number value.
|
boolean |
IsSignalingNaN()
Gets a value indicating whether this object is a signaling not-a-number
value.
|
boolean |
isZero()
Gets a value indicating whether this object's value equals 0.
|
EDecimal |
Log(EContext ctx)
Finds the natural logarithm of this object, that is, the power (exponent)
that e (the base of natural logarithms) must be raised to in order to
equal this object's value.
|
EDecimal |
Log10(EContext ctx)
Finds the base-10 logarithm of this object, that is, the power (exponent)
that the number 10 must be raised to in order to equal this
object's value.
|
static EDecimal |
Max(EDecimal first,
EDecimal second)
Gets the greater value between two decimal numbers.
|
static EDecimal |
Max(EDecimal first,
EDecimal second,
EContext ctx)
Gets the greater value between two decimal numbers.
|
static EDecimal |
MaxMagnitude(EDecimal first,
EDecimal second)
Gets the greater value between two values, ignoring their signs.
|
static EDecimal |
MaxMagnitude(EDecimal first,
EDecimal second,
EContext ctx)
Gets the greater value between two values, ignoring their signs.
|
static EDecimal |
Min(EDecimal first,
EDecimal second)
Gets the lesser value between two decimal numbers.
|
static EDecimal |
Min(EDecimal first,
EDecimal second,
EContext ctx)
Gets the lesser value between two decimal numbers.
|
static EDecimal |
MinMagnitude(EDecimal first,
EDecimal second)
Gets the lesser value between two values, ignoring their signs.
|
static EDecimal |
MinMagnitude(EDecimal first,
EDecimal second,
EContext ctx)
Gets the lesser value between two values, ignoring their signs.
|
EDecimal |
MovePointLeft(EInteger bigPlaces)
Returns a number similar to this number but with the decimal point moved to
the left.
|
EDecimal |
MovePointLeft(EInteger bigPlaces,
EContext ctx)
Returns a number similar to this number but with the decimal point moved to
the left.
|
EDecimal |
MovePointLeft(int places)
Returns a number similar to this number but with the decimal point moved to
the left.
|
EDecimal |
MovePointLeft(int places,
EContext ctx)
Returns a number similar to this number but with the decimal point moved to
the left.
|
EDecimal |
MovePointRight(EInteger bigPlaces)
Returns a number similar to this number but with the decimal point moved to
the right.
|
EDecimal |
MovePointRight(EInteger bigPlaces,
EContext ctx)
Returns a number similar to this number but with the decimal point moved to
the right.
|
EDecimal |
MovePointRight(int places)
Returns a number similar to this number but with the decimal point moved to
the right.
|
EDecimal |
MovePointRight(int places,
EContext ctx)
Returns a number similar to this number but with the decimal point moved to
the right.
|
EDecimal |
Multiply(EDecimal otherValue)
Multiplies two decimal numbers.
|
EDecimal |
Multiply(EDecimal op,
EContext ctx)
Multiplies two decimal numbers.
|
EDecimal |
MultiplyAndAdd(EDecimal multiplicand,
EDecimal augend)
Multiplies by one decimal number, and then adds another decimal number.
|
EDecimal |
MultiplyAndAdd(EDecimal op,
EDecimal augend,
EContext ctx)
Multiplies by one value, and then adds another value.
|
EDecimal |
MultiplyAndSubtract(EDecimal op,
EDecimal subtrahend,
EContext ctx)
Multiplies by one value, and then subtracts another value.
|
EDecimal |
Negate()
Gets an object with the same value as this one, but with the sign reversed.
|
EDecimal |
Negate(EContext context)
Returns a decimal number with the same value as this object but with the
sign reversed.
|
EDecimal |
NextMinus(EContext ctx)
Finds the largest value that's smaller than the given value.
|
EDecimal |
NextPlus(EContext ctx)
Finds the smallest value that's greater than the given value.
|
EDecimal |
NextToward(EDecimal otherValue,
EContext ctx)
Finds the next value that is closer to the other object's value than
this object's value.
|
static EDecimal |
PI(EContext ctx)
Finds the constant π, the circumference of a circle divided by its
diameter.
|
EDecimal |
Plus(EContext ctx)
Rounds this object's value to a given precision, using the given
rounding mode and range of exponent, and also converts negative zero
to positive zero.
|
EDecimal |
Pow(EDecimal exponent,
EContext ctx)
Raises this object's value to the given exponent.
|
EDecimal |
Pow(int exponentSmall)
Raises this object's value to the given exponent.
|
EDecimal |
Pow(int exponentSmall,
EContext ctx)
Raises this object's value to the given exponent.
|
EInteger |
Precision()
Finds the number of digits in this number's mantissa (significand).
|
EDecimal |
Quantize(EDecimal otherValue,
EContext ctx)
Returns a decimal number with the same value as this object but with the
same exponent as another decimal number.
|
EDecimal |
Quantize(EInteger desiredExponent,
EContext ctx)
Returns a decimal number with the same value but a new exponent.
|
EDecimal |
Quantize(int desiredExponentInt,
EContext ctx)
Returns a decimal number with the same value but a new exponent.
|
EDecimal |
Quantize(int desiredExponentInt,
ERounding rounding)
Returns a decimal number with the same value as this one but a new exponent.
|
EDecimal |
Reduce(EContext ctx)
Removes trailing zeros from this object's mantissa (significand).
|
EDecimal |
Remainder(EDecimal divisor,
EContext ctx)
Finds the remainder that results when dividing two arbitrary-precision
decimal numbers.
|
EDecimal |
RemainderNaturalScale(EDecimal divisor)
Calculates the remainder of a number by the formula
"this" - (("this" /
"divisor") * "divisor") |
EDecimal |
RemainderNaturalScale(EDecimal divisor,
EContext ctx)
Calculates the remainder of a number by the formula "this" - (("this" /
"divisor") * "divisor").
|
EDecimal |
RemainderNear(EDecimal divisor,
EContext ctx)
Finds the distance to the closest multiple of the given divisor, based on
the result of dividing this object's value by another
object's value.
|
EDecimal |
RoundToExponent(EInteger exponent)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary, using the HalfEven rounding mode.
|
EDecimal |
RoundToExponent(EInteger exponent,
EContext ctx)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary.
|
EDecimal |
RoundToExponent(EInteger exponent,
ERounding rounding)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary, using the given rounding mode.
|
EDecimal |
RoundToExponent(int exponentSmall)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary, using the HalfEven rounding mode.
|
EDecimal |
RoundToExponent(int exponentSmall,
EContext ctx)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary.
|
EDecimal |
RoundToExponent(int exponentSmall,
ERounding rounding)
Returns a decimal number with the same value as this object but rounded to a
new exponent if necessary.
|
EDecimal |
RoundToExponentExact(EInteger exponent,
EContext ctx)
Returns a decimal number with the same value as this object but rounded to
the given exponent, and signals an inexact flag if the result would
be inexact.
|
EDecimal |
RoundToExponentExact(int exponentSmall,
EContext ctx)
Returns a decimal number with the same value as this object but rounded to
an integer, and signals an inexact flag if the result would be
inexact.
|
EDecimal |
RoundToExponentExact(int exponentSmall,
ERounding rounding)
Returns a decimal number with the same value as this object but rounded to
an integer, and signals an inexact flag if the result would be
inexact.
|
EDecimal |
RoundToIntegerExact(EContext ctx)
Returns a decimal number with the same value as this object but rounded to
an integer, and signals an inexact flag if the result would be
inexact.
|
EDecimal |
RoundToIntegerNoRoundedFlag(EContext ctx)
Returns a decimal number with the same value as this object but rounded to
an integer, without adding the
FlagInexact or
FlagRounded flags. |
EDecimal |
RoundToIntegralExact(EContext ctx)
Deprecated.
Renamed to RoundToIntegerExact.
|
EDecimal |
RoundToIntegralNoRoundedFlag(EContext ctx)
Deprecated.
Renamed to RoundToIntegerNoRoundedFlag.
|
EDecimal |
RoundToPrecision(EContext ctx)
Rounds this object's value to a given precision, using the given
rounding mode and range of exponent.
|
EDecimal |
ScaleByPowerOfTen(EInteger bigPlaces)
Returns a number similar to this number but with the scale adjusted.
|
EDecimal |
ScaleByPowerOfTen(EInteger bigPlaces,
EContext ctx)
Returns a number similar to this number but with its scale adjusted.
|
EDecimal |
ScaleByPowerOfTen(int places)
Returns a number similar to this number but with the scale adjusted.
|
EDecimal |
ScaleByPowerOfTen(int places,
EContext ctx)
Returns a number similar to this number but with the scale adjusted.
|
int |
signum()
Gets this value's sign: -1 if negative; 1 if positive; 0 if zero.
|
EDecimal |
Sqrt(EContext ctx)
Finds the square root of this object's value.
|
EDecimal |
SquareRoot(EContext ctx)
Deprecated.
Renamed to Sqrt.
|
EDecimal |
Subtract(EDecimal otherValue)
Subtracts an arbitrary-precision decimal number from this instance and
returns the result.
|
EDecimal |
Subtract(EDecimal otherValue,
EContext ctx)
Subtracts an arbitrary-precision decimal number from this instance.
|
byte |
ToByteChecked()
Converts this number's value to a byte (from 0 to 255) if it can fit in a
byte (from 0 to 255) after truncating to an integer.
|
byte |
ToByteIfExact()
Converts this number's value to a byte (from 0 to 255) if it can fit in a
byte (from 0 to 255) without rounding to a different numerical value.
|
byte |
ToByteUnchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a byte (from 0
to 255).
|
double |
ToDouble()
Converts this value to its closest equivalent as a 64-bit floating-point
number.
|
EFloat |
ToEFloat()
Creates a binary floating-point number from this object's value.
|
EFloat |
ToEFloat(EContext ec)
Not documented yet.
|
EInteger |
ToEInteger()
Converts this value to an arbitrary-precision integer.
|
EInteger |
ToEIntegerExact()
Deprecated.
Renamed to ToEIntegerIfExact.
|
EInteger |
ToEIntegerIfExact()
Converts this value to an arbitrary-precision integer, checking whether the
fractional part of the integer would be lost.
|
String |
ToEngineeringString()
Same as toString(), except that when an exponent is used it will be a
multiple of 3.
|
EFloat |
ToExtendedFloat()
Deprecated.
Renamed to ToEFloat.
|
short |
ToInt16Checked()
Converts this number's value to a 16-bit signed integer if it can fit in a
16-bit signed integer after truncating to an integer.
|
short |
ToInt16IfExact()
Converts this number's value to a 16-bit signed integer if it can fit in a
16-bit signed integer without rounding to a different numerical
value.
|
short |
ToInt16Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 16-bit
signed integer.
|
int |
ToInt32Checked()
Converts this number's value to a 32-bit signed integer if it can fit in a
32-bit signed integer after truncating to an integer.
|
int |
ToInt32IfExact()
Converts this number's value to a 32-bit signed integer if it can fit in a
32-bit signed integer without rounding to a different numerical
value.
|
int |
ToInt32Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 32-bit
signed integer.
|
long |
ToInt64Checked()
Converts this number's value to a 64-bit signed integer if it can fit in a
64-bit signed integer after truncating to an integer.
|
long |
ToInt64IfExact()
Converts this number's value to a 64-bit signed integer if it can fit in a
64-bit signed integer without rounding to a different numerical
value.
|
long |
ToInt64Unchecked()
Truncates this number's value to an integer and returns the
least-significant bits of its two's-complement form as a 64-bit
signed integer.
|
String |
ToPlainString()
Converts this value to a string, but without using exponential notation.
|
float |
ToSingle()
Converts this value to its closest equivalent as a 32-bit floating-point
number.
|
String |
toString()
Converts this value to a string.
|
EDecimal |
Ulp()
Returns the unit in the last place.
|
public static final EDecimal NaN
public static final EDecimal NegativeInfinity
public static final EDecimal NegativeZero
public static final EDecimal One
public static final EDecimal PositiveInfinity
public static final EDecimal SignalingNaN
public static final EDecimal Ten
public static final EDecimal Zero
public final EInteger getExponent()
public final boolean isFinite()
true if this object is finite (not infinity or not-a-number
(NaN)); otherwise, false.public final boolean isNegative()
true if this object is negative, including negative zero;
otherwise, false.public final boolean isZero()
true if this object's value equals 0; otherwise, . false.public final EInteger getMantissa()
public final int signum()
public final EInteger getUnsignedMantissa()
public static EDecimal Create(int mantissaSmall, int exponentSmall)
exponent*10^mantissamantissaSmall - The parameter mantissaSmall is not documented
yet.exponentSmall - The parameter exponentSmall is not documented
yet.public static EDecimal Create(EInteger mantissa, EInteger exponent)
exponent*10^mantissamantissa - The parameter mantissa is not documented yet.exponent - The parameter exponent is not documented yet.NullPointerException - The parameter mantissa or
exponent is null.public static EDecimal CreateNaN(EInteger diag)
diag - A number to use as diagnostic information associated with this
object. If none is needed, should be zero.NullPointerException - The parameter diag is null or
is less than 0.public static EDecimal CreateNaN(EInteger diag, boolean signaling, boolean negative, EContext ctx)
diag - A number to use as diagnostic information associated with this
object. If none is needed, should be zero.signaling - Whether the return value will be signaling (true) or quiet
(false).negative - Whether the return value is negative.ctx - An arithmetic context to control the precision (in decimal
digits) of the diagnostic information. The rounding and exponent
range of this context will be ignored. Can be null. The only flag
that can be signaled in this context is FlagInvalid, which happens if
diagnostic information needs to be truncated and too much memory is
required to do so.NullPointerException - The parameter diag is null or
is less than 0.public static EDecimal FromDouble(double dbl)
ExtendedDecimal.FromDouble(0.1f)), since not all decimal
numbers can be converted to exact binary numbers (in the example
given, the resulting arbitrary-precision decimal will be the value of
the closest "double" to 0.1, not 0.1 exactly). To create an
arbitrary-precision decimal number from a decimal number, use
FromString instead in most cases (for example:
ExtendedDecimal.FromString("0.1")).dbl - A 64-bit floating-point number.dbl.public static EDecimal FromEInteger(EInteger bigint)
bigint - An arbitrary-precision integer.@Deprecated public static EDecimal FromExtendedFloat(EFloat ef)
ef - The parameter ef is not documented yet.public static EDecimal FromEFloat(EFloat bigfloat)
bigfloat - An arbitrary-precision binary floating-point number.NullPointerException - The parameter bigfloat is null.public static EDecimal FromInt32(int valueSmaller)
valueSmaller - A 32-bit signed integer.public static EDecimal FromInt64(long valueSmall)
valueSmall - A 64-bit signed integer.public static EDecimal FromSingle(float flt)
ExtendedDecimal.FromSingle(0.1f)), since not all decimal
numbers can be converted to exact binary numbers (in the example
given, the resulting arbitrary-precision decimal will be the the
value of the closest "float" to 0.1, not 0.1 exactly). To create an
arbitrary-precision decimal number from a decimal number, use
FromString instead in most cases (for example:
ExtendedDecimal.FromString("0.1")).flt - A 32-bit floating-point number.flt.public static EDecimal FromString(String str)
FromString(String, int, int, EContext) for more information.str - A string that represents a number.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public static EDecimal FromString(String str, EContext ctx)
FromString(String, int, int, EContext) for more information.str - A string that represents a number.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public static EDecimal FromString(String str, int offset, int length)
FromString(String, int, int, EContext) for more information.str - A string that represents a number.offset - A zero-based index showing where the desired portion of str begins.length - The length, in code units, of the desired portion of str (but not more than str 's length).NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public static EDecimal FromString(String str, int offset, int length, EContext ctx)
Creates a decimal number from a text string that represents a number.
The format of the string generally consists of:
The string can also be "-INF", "-Infinity", "Infinity", "INF", quiet NaN ("NaN" /"-NaN") followed by any number of digits, or signaling NaN ("sNaN" /"-sNaN") followed by any number of digits, all in any combination of upper and lower case.
All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U + 0030 to U + 0039). The string is not allowed to contain white space characters, including spaces.
str - A text string, a portion of which represents a number.offset - A zero-based index that identifies the start of the number.length - The length of the number within the string.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is not a correctly
formatted number string.public static EDecimal Max(EDecimal first, EDecimal second, EContext ctx)
first - The first value to compare.second - The second value to compare.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public static EDecimal Max(EDecimal first, EDecimal second)
first - An arbitrary-precision decimal number.second - Another arbitrary-precision decimal number.public static EDecimal MaxMagnitude(EDecimal first, EDecimal second, EContext ctx)
first - The first value to compare.second - The second value to compare.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public static EDecimal MaxMagnitude(EDecimal first, EDecimal second)
first - The first value to compare.second - The second value to compare.public static EDecimal Min(EDecimal first, EDecimal second, EContext ctx)
first - The first value to compare.second - The second value to compare.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public static EDecimal Min(EDecimal first, EDecimal second)
first - The first value to compare.second - The second value to compare.public static EDecimal MinMagnitude(EDecimal first, EDecimal second, EContext ctx)
first - The first value to compare.second - The second value to compare.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public static EDecimal MinMagnitude(EDecimal first, EDecimal second)
first - The first value to compare.second - The second value to compare.public static EDecimal PI(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as π can never be represented exactly..ctx is null
or the precision is unlimited (the context's Precision property is
0).public EDecimal Abs()
public EDecimal CopySign(EDecimal other)
other - A number whose sign will be copied.NullPointerException - The parameter other is null.public EDecimal Abs(EContext context)
context - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.public EDecimal Add(EDecimal otherValue)
otherValue - An arbitrary-precision decimal number.public EDecimal Add(EDecimal otherValue, EContext ctx)
otherValue - The number to add to.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.public int compareTo(EDecimal other)
This method is not consistent with the Equals method because two different numbers with the same mathematical value, but different exponents, will compare as equal.
In this method, negative zero and positive zero are considered equal.
If this object or the other object is a quiet NaN or signaling NaN, this method will not trigger an error. Instead, NaN will compare greater than any other number, including infinity. Two different NaN values will be considered equal.
compareTo in interface Comparable<EDecimal>other - An arbitrary-precision decimal number.other is null, or 0 if both values are equal.public int CompareToBinary(EFloat other)
other - The other object to compare. Can be null.public EDecimal CompareToSignal(EDecimal other, EContext ctx)
In this method, negative zero and positive zero are considered equal.
If this object or the other object is a quiet NaN or signaling NaN, this method will return a quiet NaN and will signal a FlagInvalid flag.
other - An arbitrary-precision decimal number.ctx - An arithmetic context. The precision, rounding, and exponent
range are ignored. If HasFlags of the context is true, will
store the flags resulting from the operation (the flags are in
addition to the pre-existing flags). Can be null.public int CompareToTotalMagnitude(EDecimal other)
other - An arbitrary-precision decimal number to compare with this one.public int CompareToTotal(EDecimal other, EContext ctx)
other - An arbitrary-precision decimal number to compare with this one.ctx - An arithmetic context. Flags will be set in this context only if
HasFlags and IsSimplified of the context are true and
only if an operand needed to be rounded before carrying out the
operation. Can be null.public int CompareToTotal(EDecimal other)
other - An arbitrary-precision decimal number to compare with this one.public EDecimal CompareToWithContext(EDecimal other, EContext ctx)
In this method, negative zero and positive zero are considered equal.
If this object or the other object is a quiet NaN or signaling NaN, this method returns a quiet NaN, and will signal a FlagInvalid flag if either is a signaling NaN.
other - An arbitrary-precision decimal number.ctx - An arithmetic context. The precision, rounding, and exponent
range are ignored. If HasFlags of the context is true, will
store the flags resulting from the operation (the flags are in
addition to the pre-existing flags). Can be null.public EDecimal Divide(EDecimal divisor)
divisor - An arbitrary-precision decimal number to divide by.public EDecimal Divide(EDecimal divisor, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.ctx is null or ctx 's
precision is 0, and the result would have a nonterminating decimal
expansion; or, the rounding mode is ERounding.None and the result is
not exact.@Deprecated public EDecimal[] DivideAndRemainderNaturalScale(EDecimal divisor)
divisor - An arbitrary-precision decimal number to divide by.@Deprecated public EDecimal[] DivideAndRemainderNaturalScale(EDecimal divisor, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. This context will be used only in
the division portion of the remainder calculation; as a result, it's
possible for the remainder to have a higher precision than given in
this context. Flags will be set on the given context only if the
context's HasFlags is true and the integer part of the
division result doesn't fit the precision and exponent range without
rounding. Can be null, in which the precision is unlimited and no
additional rounding, other than the rounding down to an integer after
division, is needed.public EDecimal[] DivRemNaturalScale(EDecimal divisor)
divisor - An arbitrary-precision decimal number to divide by.public EDecimal[] DivRemNaturalScale(EDecimal divisor, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. This context will be used only in
the division portion of the remainder calculation; as a result, it's
possible for the remainder to have a higher precision than given in
this context. Flags will be set on the given context only if the
context's HasFlags is true and the integer part of the
division result doesn't fit the precision and exponent range without
rounding. Can be null, in which the precision is unlimited and no
additional rounding, other than the rounding down to an integer after
division, is needed.public EDecimal DivideToExponent(EDecimal divisor, long desiredExponentSmall, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentSmall - The desired exponent. A negative number places
the cutoff point to the right of the usual decimal point (so a
negative number means the number of decimal places to round to). A
positive number places the cutoff point to the left of the usual
decimal point.ctx - An arithmetic context object to control the rounding mode to use
if the result must be scaled down to have the same exponent as this
value. If the precision given in the context is other than 0, calls
the Quantize method with both arguments equal to the result of the
operation (and can signal FlagInvalid and return NaN if the result
doesn't fit the given precision). If HasFlags of the context
is true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal DivideToExponent(EDecimal divisor, int desiredExponentInt, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentInt - The desired exponent. A negative number places the
cutoff point to the right of the usual decimal point (so a negative
number means the number of decimal places to round to). A positive
number places the cutoff point to the left of the usual decimal
point.ctx - An arithmetic context object to control the rounding mode to use
if the result must be scaled down to have the same exponent as this
value. If the precision given in the context is other than 0, calls
the Quantize method with both arguments equal to the result of the
operation (and can signal FlagInvalid and return NaN if the result
doesn't fit the given precision). If HasFlags of the context
is true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal DivideToExponent(EDecimal divisor, long desiredExponentSmall, ERounding rounding)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentSmall - The desired exponent. A negative number places
the cutoff point to the right of the usual decimal point (so a
negative number means the number of decimal places to round to). A
positive number places the cutoff point to the left of the usual
decimal point.rounding - The rounding mode to use if the result must be scaled down
to have the same exponent as this value.public EDecimal DivideToExponent(EDecimal divisor, int desiredExponentInt, ERounding rounding)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentInt - The desired exponent. A negative number places the
cutoff point to the right of the usual decimal point (so a negative
number means the number of decimal places to round to). A positive
number places the cutoff point to the left of the usual decimal
point.rounding - The rounding mode to use if the result must be scaled down
to have the same exponent as this value.public EDecimal DivideToExponent(EDecimal divisor, EInteger exponent, EContext ctx)
divisor - An arbitrary-precision decimal number to divide by.exponent - The desired exponent. A negative number places the cutoff
point to the right of the usual decimal point (so a negative number
means the number of decimal places to round to). A positive number
places the cutoff point to the left of the usual decimal point.ctx - An arithmetic context object to control the rounding mode to use
if the result must be scaled down to have the same exponent as this
value. If the precision given in the context is other than 0, calls
the Quantize method with both arguments equal to the result of the
operation (and can signal FlagInvalid and return NaN if the result
doesn't fit the given precision). If HasFlags of the context
is true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal DivideToExponent(EDecimal divisor, EInteger exponent)
divisor - An arbitrary-precision decimal number to divide by.exponent - The desired exponent. A negative number places the cutoff
point to the right of the usual decimal point (so a negative number
means the number of decimal places to round to). A positive number
places the cutoff point to the left of the usual decimal point.public EDecimal DivideToExponent(EDecimal divisor, long desiredExponentSmall)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentSmall - The desired exponent. A negative number places
the cutoff point to the right of the usual decimal point (so a
negative number means the number of decimal places to round to). A
positive number places the cutoff point to the left of the usual
decimal point.public EDecimal DivideToExponent(EDecimal divisor, int desiredExponentInt)
divisor - An arbitrary-precision decimal number to divide by.desiredExponentInt - The desired exponent. A negative number places the
cutoff point to the right of the usual decimal point (so a negative
number means the number of decimal places to round to). A positive
number places the cutoff point to the left of the usual decimal
point.public EDecimal DivideToExponent(EDecimal divisor, EInteger desiredExponent, ERounding rounding)
divisor - An arbitrary-precision decimal number to divide by.desiredExponent - The desired exponent. A negative number places the
cutoff point to the right of the usual decimal point (so a negative
number means the number of decimal places to round to). A positive
number places the cutoff point to the left of the usual decimal
point.rounding - The rounding mode to use if the result must be scaled down
to have the same exponent as this value.public EDecimal DivideToIntegerNaturalScale(EDecimal divisor)
divisor - An arbitrary-precision decimal number to divide by.public EDecimal DivideToIntegerNaturalScale(EDecimal divisor, EContext ctx)
divisor - The number to divide by.ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the integer part of the result. Flags will be
set on the given context only if the context's HasFlags is
true and the integer part of the result doesn't fit the precision and
exponent range without rounding. Can be null, in which the precision
is unlimited and no additional rounding, other than the rounding down
to an integer after division, is needed.public EDecimal DivideToIntegerZeroScale(EDecimal divisor, EContext ctx)
divisor - The number to divide by.ctx - An arithmetic context object to control the precision. The
rounding and exponent range settings of this context are ignored. If
HasFlags of the context is true, will also store the flags
resulting from the operation (the flags are in addition to the
pre-existing flags). Can be null, in which case the precision is
unlimited.public EDecimal DivideToSameExponent(EDecimal divisor, ERounding rounding)
divisor - The number to divide by.rounding - The rounding mode to use if the result must be scaled down
to have the same exponent as this value.public boolean equals(EDecimal other)
other - An arbitrary-precision decimal number.true if this object's mantissa (significand) and exponent
are equal to those of another object; otherwise, false.public boolean equals(Object obj)
public EDecimal Exp(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as the exponential function's results are generally
not exact. (Unlike in the General Decimal Arithmetic
Specification, any rounding mode is allowed.).ctx is null
or the precision is unlimited (the context's Precision property is
0).public int hashCode()
public boolean IsInfinity()
true if this object is positive or negative infinity;
otherwise, false.public boolean IsNaN()
true if this object is not a number (NaN); otherwise, false.public boolean IsNegativeInfinity()
true if this object is negative infinity; otherwise, false.public boolean IsPositiveInfinity()
true if this object is positive infinity; otherwise, false.public boolean IsQuietNaN()
true if this object is a quiet not-a-number value;
otherwise, false.public boolean IsSignalingNaN()
true if this object is a signaling not-a-number value;
otherwise, false.public EDecimal Log(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as the ln function's results are generally not
exact. (Unlike in the General Decimal Arithmetic Specification,
any rounding mode is allowed.).ctx is null or the precision is unlimited (the context's
Precision property is 0). Signals no flags and returns negative
infinity if this object's value is 0.public EDecimal Log10(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as the ln function's results are generally not
exact. (Unlike in the General Decimal Arithmetic Specification,
any rounding mode is allowed.).ctx is null
or the precision is unlimited (the context's Precision property is
0).public EDecimal MovePointLeft(int places)
places - The number of decimal places to move the decimal point to the
left. If this number is negative, instead moves the decimal point to
the right by this number's absolute value.places, but not to
more than 0.public EDecimal MovePointLeft(int places, EContext ctx)
places - The number of decimal places to move the decimal point to the
left. If this number is negative, instead moves the decimal point to
the right by this number's absolute value.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.places, but not to
more than 0.public EDecimal MovePointLeft(EInteger bigPlaces)
bigPlaces - The number of decimal places to move the decimal point to
the left. If this number is negative, instead moves the decimal point
to the right by this number's absolute value.bigPlaces, but not
to more than 0.public EDecimal MovePointLeft(EInteger bigPlaces, EContext ctx)
bigPlaces - The number of decimal places to move the decimal point to
the left. If this number is negative, instead moves the decimal point
to the right by this number's absolute value.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.bigPlaces, but not
to more than 0.public EDecimal MovePointRight(int places)
places - The number of decimal places to move the decimal point to the
right. If this number is negative, instead moves the decimal point to
the left by this number's absolute value.places, but not to
more than 0.public EDecimal MovePointRight(int places, EContext ctx)
places - The number of decimal places to move the decimal point to the
right. If this number is negative, instead moves the decimal point to
the left by this number's absolute value.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.places, but not to
more than 0.public EDecimal MovePointRight(EInteger bigPlaces)
bigPlaces - The number of decimal places to move the decimal point to
the right. If this number is negative, instead moves the decimal
point to the left by this number's absolute value.bigPlaces, but not
to more than 0.public EDecimal MovePointRight(EInteger bigPlaces, EContext ctx)
bigPlaces - The number of decimal places to move the decimal point to
the right. If this number is negative, instead moves the decimal
point to the left by this number's absolute value.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.bigPlaces, but not
to more than 0.public EDecimal Multiply(EDecimal otherValue)
otherValue - Another decimal number.public EDecimal Multiply(EDecimal op, EContext ctx)
op - Another decimal number.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public EDecimal MultiplyAndAdd(EDecimal multiplicand, EDecimal augend)
multiplicand - The value to multiply.augend - The value to add.multiplicand + augend.public EDecimal MultiplyAndAdd(EDecimal op, EDecimal augend, EContext ctx)
op - The value to multiply.augend - The value to add.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed. If
the precision doesn't indicate a simplified arithmetic, rounding and
precision/exponent adjustment is done only once, namely, after
multiplying and adding.public EDecimal MultiplyAndSubtract(EDecimal op, EDecimal subtrahend, EContext ctx)
op - The value to multiply.subtrahend - The value to subtract.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed. If
the precision doesn't indicate a simplified arithmetic, rounding and
precision/exponent adjustment is done only once, namely, after
multiplying and subtracting.NullPointerException - The parameter op or subtrahend is null.public EDecimal Negate()
public EDecimal Negate(EContext context)
context - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public EDecimal NextMinus(EContext ctx)
ctx - An arithmetic context object to control the precision and
exponent range of the result. The rounding mode from this context is
ignored. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags).ctx is null, the precision is 0, or ctx has an unlimited
exponent range.public EDecimal NextPlus(EContext ctx)
ctx - An arithmetic context object to control the precision and
exponent range of the result. The rounding mode from this context is
ignored. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags).ctx is null, the precision is 0, or ctx has
an unlimited exponent range.public EDecimal NextToward(EDecimal otherValue, EContext ctx)
otherValue - An arbitrary-precision decimal number that the return
value will approach.ctx - An arithmetic context object to control the precision and
exponent range of the result. The rounding mode from this context is
ignored. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags).ctx is null, the precision is 0, or ctx has
an unlimited exponent range.public EDecimal Plus(EContext ctx)
ctx - A context for controlling the precision, rounding mode, and
exponent range. Can be null, in which case the precision is unlimited
and rounding isn't needed.ctx is
null or the precision and exponent range are unlimited.public EDecimal Pow(EDecimal exponent, EContext ctx)
exponent - An arbitrary-precision decimal number expressing the
exponent to raise this object's value to.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.ctx is null or the precision is unlimited (the context's Precision
property is 0), and the exponent has a fractional part.public EDecimal Pow(int exponentSmall, EContext ctx)
exponentSmall - The exponent to raise this object's value to.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public EDecimal Pow(int exponentSmall)
exponentSmall - The exponent to raise this object's value to.public EInteger Precision()
public EDecimal Quantize(EInteger desiredExponent, EContext ctx)
Note that this is not always the same as rounding to a given number of decimal places, since it can fail if the difference between this value's exponent and the desired exponent is too big, depending on the maximum precision. If rounding to a number of decimal places is desired, it's better to use the RoundToExponent and RoundToIntegral methods instead.
Remark: This method can be used to implement fixed-point decimal arithmetic, in which each decimal number has a fixed number of digits after the decimal point. The following code example returns a fixed-point number with up to 20 digits before and exactly 5 digits after the decimal point:
// After performing arithmetic operations, adjust // the
number to 5 digits after the decimal point number = number.Quantize(
EInteger.FromInt32(-5), // five digits after the decimal point
EContext.ForPrecision(25) // 25-digit precision); A fixed-point decimal arithmetic in which no digits come after the decimal point (a desired exponent of 0) is considered an "integer arithmetic".
desiredExponent - The desired exponent for the result. The exponent is
the number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision and rounding of the
result. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags). Can be null, in which case the default
rounding mode is HalfEven.public EDecimal Quantize(int desiredExponentInt, ERounding rounding)
Remark: This method can be used to implement fixed-point decimal arithmetic, in which a fixed number of digits come after the decimal point. A fixed-point decimal arithmetic in which no digits come after the decimal point (a desired exponent of 0) is considered an "integer arithmetic".
desiredExponentInt - The desired exponent for the result. The exponent
is the number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.rounding - A rounding mode to use in case the result needs to be
rounded to fit the given exponent.public EDecimal Quantize(int desiredExponentInt, EContext ctx)
Note that this is not always the same as rounding to a given number of decimal places, since it can fail if the difference between this value's exponent and the desired exponent is too big, depending on the maximum precision. If rounding to a number of decimal places is desired, it's better to use the RoundToExponent and RoundToIntegral methods instead.
Remark: This method can be used to implement fixed-point decimal arithmetic, in which each decimal number has a fixed number of digits after the decimal point. The following code example returns a fixed-point number with up to 20 digits before and exactly 5 digits after the decimal point:
// After performing arithmetic operations, adjust // the
number to 5 digits after the decimal point number =
number.Quantize(-5, // five digits after the decimal point
EContext.ForPrecision(25) // 25-digit precision); A fixed-point decimal arithmetic in which no digits come after the decimal point (a desired exponent of 0) is considered an "integer arithmetic".
desiredExponentInt - The desired exponent for the result. The exponent
is the number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision and rounding of the
result. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags). Can be null, in which case the default
rounding mode is HalfEven.public EDecimal Quantize(EDecimal otherValue, EContext ctx)
Note that this is not always the same as rounding to a given number of decimal places, since it can fail if the difference between this value's exponent and the desired exponent is too big, depending on the maximum precision. If rounding to a number of decimal places is desired, it's better to use the RoundToExponent and RoundToIntegral methods instead.
Remark: This method can be used to implement fixed-point decimal arithmetic, in which a fixed number of digits come after the decimal point. A fixed-point decimal arithmetic in which no digits come after the decimal point (a desired exponent of 0) is considered an "integer arithmetic".
otherValue - A decimal number containing the desired exponent of the
result. The mantissa (significand) is ignored. The exponent is the
number of fractional digits in the result, expressed as a negative
number. Can also be positive, which eliminates lower-order places
from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision and rounding of the
result. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags). Can be null, in which case the default
rounding mode is HalfEven.public EDecimal Reduce(EContext ctx)
If this object's value is 0, changes the exponent to 0.
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and rounding isn't needed.public EDecimal Remainder(EDecimal divisor, EContext ctx)
divisor - The number to divide by.ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. This context will be used both in
the division portion and in the remainder portion of the remainder
calculation. If HasFlags of the context is true, will also
store the flags resulting from the operation (the flags are in
addition to the pre-existing flags). Can be null, in which case the
precision is unlimited and no additional rounding (other than the
rounding from integer division) is needed.public EDecimal RemainderNaturalScale(EDecimal divisor)
"this" - (("this" /
"divisor") * "divisor")divisor - The number to divide by.public EDecimal RemainderNaturalScale(EDecimal divisor, EContext ctx)
divisor - The number to divide by.ctx - An arithmetic context object to control the precision, rounding,
and exponent range of the result. This context will be used only in
the division portion of the remainder calculation; as a result, it's
possible for the return value to have a higher precision than given
in this context. Flags will be set on the given context only if the
context's HasFlags is true and the integer part of the
division result doesn't fit the precision and exponent range without
rounding. Can be null, in which the precision is unlimited and no
additional rounding, other than the rounding down to an integer after
division, is needed.public EDecimal RemainderNear(EDecimal divisor, EContext ctx)
divisor - The number to divide by.ctx - An arithmetic context object to control the precision. The
rounding and exponent range settings of this context are ignored (the
rounding mode is always treated as HalfEven). If HasFlags of
the context is true, will also store the flags resulting from the
operation (the flags are in addition to the pre-existing flags). Can
be null, in which the precision is unlimited.public EDecimal RoundToExponent(EInteger exponent, EContext ctx)
exponent - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToExponent(EInteger exponent)
exponent - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.public EDecimal RoundToExponent(EInteger exponent, ERounding rounding)
exponent - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.rounding - Desired mode for rounding this number's value.public EDecimal RoundToExponent(int exponentSmall)
exponentSmall - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.public EDecimal RoundToExponent(int exponentSmall, EContext ctx)
exponentSmall - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToExponent(int exponentSmall, ERounding rounding)
exponentSmall - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.rounding - The desired mode to use to round the given number to the
given exponent.public EDecimal RoundToExponentExact(EInteger exponent, EContext ctx)
exponent - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToExponentExact(int exponentSmall, EContext ctx)
exponentSmall - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToExponentExact(int exponentSmall, ERounding rounding)
exponentSmall - The minimum exponent the result can have. This is the
maximum number of fractional digits in the result, expressed as a
negative number. Can also be positive, which eliminates lower-order
places from the number. For example, -3 means round to the thousandth
(10^-3, 0.0001), and 3 means round to the thousand (10^3, 1000). A
value of 0 rounds the number to an integer.rounding - Desired mode for rounding this object's value.public EDecimal RoundToIntegerExact(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToIntegerNoRoundedFlag(EContext ctx)
FlagInexact or
FlagRounded flags.ctx - An arithmetic context to control precision and rounding of the
result. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags), except that this function will never add the
FlagRounded and FlagInexact flags (the only
difference between this and RoundToExponentExact). Can be null, in
which case the default rounding mode is HalfEven.@Deprecated public EDecimal RoundToIntegralExact(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the default rounding mode is HalfEven.@Deprecated public EDecimal RoundToIntegralNoRoundedFlag(EContext ctx)
FlagInexact or
FlagRounded flags.ctx - An arithmetic context to control precision and rounding of the
result. If HasFlags of the context is true, will also store
the flags resulting from the operation (the flags are in addition to
the pre-existing flags), except that this function will never add the
FlagRounded and FlagInexact flags (the only
difference between this and RoundToExponentExact). Can be null, in
which case the default rounding mode is HalfEven.public EDecimal RoundToPrecision(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.ctx is
null or the precision and exponent range are unlimited.public EDecimal ScaleByPowerOfTen(int places)
places - The power of 10 to scale by.public EDecimal ScaleByPowerOfTen(int places, EContext ctx)
places - The power of 10 to scale by.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.public EDecimal ScaleByPowerOfTen(EInteger bigPlaces)
bigPlaces - The power of 10 to scale by.public EDecimal ScaleByPowerOfTen(EInteger bigPlaces, EContext ctx)
bigPlaces - The power of 10 to scale by.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.bigPlaces.public EDecimal Sqrt(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as the square root function's results are generally
not exact for many inputs. (Unlike in the General Decimal
Arithmetic Specification, any rounding mode is allowed.).ctx is null or
the precision is unlimited (the context's Precision property is 0).@Deprecated public EDecimal SquareRoot(EContext ctx)
ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). This parameter
can't be null, as the square root function's results are generally
not exact for many inputs. (Unlike in the General Decimal
Arithmetic Specification, any rounding mode is allowed.).ctx is null or
the precision is unlimited (the context's Precision property is 0).public EDecimal Subtract(EDecimal otherValue)
otherValue - The number to subtract from this instance's value.public EDecimal Subtract(EDecimal otherValue, EContext ctx)
otherValue - The number to subtract from this instance's value.ctx - An arithmetic context to control precision, rounding, and
exponent range of the result. If HasFlags of the context is
true, will also store the flags resulting from the operation (the
flags are in addition to the pre-existing flags). Can be null, in
which case the precision is unlimited and no rounding is needed.NullPointerException - The parameter otherValue is
null.public double ToDouble()
If this value is a NaN, sets the high bit of the 64-bit floating point number's significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object's unsigned mantissa (significand), and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN. Unfortunately, in the .NET implementation, the return value of this method may be a quiet NaN even if a signaling NaN would otherwise be generated.
public EInteger ToEInteger()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).@Deprecated public EInteger ToEIntegerExact()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).ArithmeticException - This object's value is not an exact integer.public EInteger ToEIntegerIfExact()
ArithmeticException - This object's value is infinity or
not-a-number (NaN).ArithmeticException - This object's value is not an exact integer.public String ToEngineeringString()
@Deprecated public EFloat ToExtendedFloat()
public EFloat ToEFloat()
public String ToPlainString()
public float ToSingle()
If this value is a NaN, sets the high bit of the 32-bit floating point number's significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object's unsigned mantissa (significand), and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN. Unfortunately, in the .NET implementation, the return value of this method may be a quiet NaN even if a signaling NaN would otherwise be generated.
public String toString()
public EDecimal Ulp()
public EFloat ToEFloat(EContext ec)
ec - The parameter ec is not documented yet.public byte ToByteChecked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than 0 or greater than 255.public byte ToByteUnchecked()
public byte ToByteIfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than 0 or greater than 255.public static EDecimal FromByte(byte inputByte)
inputByte - The number to convert as a byte (from 0 to 255).public short ToInt16Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -32768 or greater than 32767.public short ToInt16Unchecked()
public short ToInt16IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -32768 or greater than 32767.public static EDecimal FromInt16(short inputInt16)
inputInt16 - The number to convert as a 16-bit signed integer.public int ToInt32Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -2147483648 or greater than
2147483647.public int ToInt32Unchecked()
public int ToInt32IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -2147483648 or greater than
2147483647.public long ToInt64Checked()
ArithmeticException - This value is infinity or not-a-number, or
the truncated integer is less than -9223372036854775808 or greater
than 9223372036854775807.public long ToInt64Unchecked()
public long ToInt64IfExact()
ArithmeticException - This value is infinity or not-a-number, is not
an exact integer, or is less than -9223372036854775808 or greater
than 9223372036854775807.CBOR for Java documentation, generated in 2016.