Precision used to round _decimal operation results. Every result will be adjusted to fit the specified precision. Use DecimalControl to query or set the context precision
Shorthand notations for Decimal types
Shorthand notations for Decimal types
Returns the next value after or before x, toward y.
Root object for all _decimal exceptions
Thrown if the denominator of a _decimal division operation is zero.
Thrown if the result of a _decimal operation was rounded to fit in the destination format.
Thrown if any operand of a _decimal operation is not a number or si not finite
Thrown if the result of a _decimal operation exceeds the largest finite number of the destination format.
Thrown if the result of a _decimal operation is smaller the smallest finite number of the destination format.
IEEE-754-2008 floating point categories
These flags indicate that an error has occurred. They indicate that a 0, NaN or an infinity value has been generated, that a result is inexact, or that a signalling NaN has been encountered. If the corresponding traps are set using DecimalControl, an exception will be thrown after setting these error flags.
Undocumented in source.
Rounding modes. To better understand how rounding is performed, consult the table below.
Precision used to round _decimal operation results. Every result will be adjusted to fit the specified precision. Use DecimalControl to query or set the context precision
Undocumented in source.
Creates a quiet NaN value using the specified payload Notes: Payloads are masked to fit the current representation, having a limited bit width of to mant_dig - 2;
Creates a quiet NaN value using the specified payload Notes: Payloads are masked to fit the current representation, having a limited bit width of to mant_dig - 2;
Calculates the arc cosine of x, returning a value ranging from 0 to π. Exceptions:
InvalidOperationException | x is signaling NaN or |x| > 1.0 |
InexactException | the result is inexact |
Calculates the inverse hyperbolic cosine of x Exceptions:
InvalidOperationException | x is signaling NaN or x < 1.0 |
InexactException | the result is inexact |
Computes whether two values are approximately equal, admitting a maximum relative difference, or a maximum absolute difference.
Calculates the arc sine of x, returning a value ranging from -π/2 to +π/2. Exceptions:
InvalidOperationException | x is signaling NaN or |x| > 1.0 |
InexactException | the result is inexact |
Calculates the inverse hyperbolic sine of x Exceptions:
InvalidOperationException | x is signaling NaN |
UnderflowException | the result is too small to be represented |
InexactException | the result is inexact |
Calculates the arc tangent of x, returning a value ranging from -π/2 to π/2. Exceptions:
InvalidOperationException | x is signaling NaN |
InexactException | the result is inexact |
UnderflowException | the result is too small to be represented |
Calculates the arc tangent of y / x, returning a value ranging from -π to π. Exceptions:
InvalidOperationException | x or y is signaling NaN |
InexactException | the result is inexact |
UnderflowException | the result is too small to be represented |
Calculates the arc tangent of y / x divided by π, returning a value ranging from -1 to 1. Exceptions:
InvalidOperationException | x or y is signaling NaN |
InexactException | the result is inexact |
UnderflowException | the result is too small to be represented |
Calculates the inverse hyperbolic tangent of x Exceptions:
InvalidOperationException | x is signaling NaN or |x| > 1.0 |
DivisionByZeroException | |x| = 1.0 |
UnderflowException | the result is too small to be represented |
InexactException | the result is inexact |
Calculates the arc tangent of x divided by π, returning a value ranging from -1/2 to 1/2. Exceptions:
InvalidOperationException | x is signaling NaN |
InexactException | the result is inexact |
UnderflowException | the result is too small to be represented |
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Computes the cubic root of x
Returns the value of x rounded upward to the next integer (toward positive infinity). This operation is silent, doesn't throw any exception.
Defines a total order on all _decimal values.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source.
Undocumented in source.
Undocumented in source.
Undocumented in source.
Undocumented in source.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Computes (1 + x)n where n is an integer
Copies the sign of a _decimal value to another. This operation is silent, no error flags are set and no exceptions are thrown.
Returns cosine of x.
Calculates the hyperbolic cosine of x.
Returns cosine of xπ.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Returns the decimal class where x falls into. This operation is silent, no exception flags are set and no exceptions are thrown.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source.
Sums xi * yi using a higher precision, rounding only once at the end.
Calculates ex
Calculates 10x
Calculates 10x - 1
Undocumented in source. Be warned that the author may not have intended to support it.
Calculates 2x
Calculates 2x - 1
Undocumented in source. Be warned that the author may not have intended to support it.
Calculates ex - 1
Undocumented in source.
Calculates |x|. This operation is silent, no error flags are set and no exceptions are thrown.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Returns the positive difference between x and y. If x ≤ y, retuns 0.0
Returns the value of x rounded downward to the previous integer (toward negative infinity). This operation is silent, doesn't throw any exception.
Returns (x * y) + z, rounding only once according to the current precision and rounding mode
Returns the larger _decimal value between x and y
Returns the larger _decimal value between absolutes of x and y
Returns the smaller _decimal value between x and y
Returns the smaller _decimal value between absolutes of x and y
Calculates the remainder of the division x / y
Separates _decimal _value into coefficient and exponent. This operation is silent, doesn't throw any exception.
Converts the specified value from internal encoding from/to densely packed decimal encoding Notes: Decimal values are represented internaly using binary integer _decimal encoding, supported by Intel (BID). This function converts the specified value to/from densely packed _decimal encoding, supported by IBM (DPD). Please note that a DPD encoded _decimal cannot be passed to a function from this module, there is no way to determine if a _decimal value is BID-encoded or DPD-encoded, all functions will assume a BID-encoding.
Converts the specified value to/from Microsoft currency data type;
Converts the specified value to/from Microsoft _decimal data type;
Undocumented in source. Be warned that the author may not have intended to support it.
Extracts the current payload from a NaN value Note: These functions do not check if x is truly a NaN value before extracting the payload. Using them on finite values will extract a part of the coefficient
Undocumented in source. Be warned that the author may not have intended to support it.
Calculates the length of the hypotenuse of a right-angled triangle with sides of length x and y. The hypotenuse is the value of the square root of the sums of the squares of x and y.
Returns the 10-exponent of x as a signed integral value..
Determines if x is canonical. This operation is silent, no error flags are set and no exceptions are thrown.
Compares two _decimal operands for equality
Determines if x is a finite value. This operation is silent, no error flags are set and no exceptions are thrown.
Compares two _decimal operands. This operation is silent, no exception flags are set and no exceptions are thrown.
Checks if two _decimal values are identical
Determines if x represents infinity. This operation is silent, no error flags are set and no exceptions are thrown.
Compares two _decimal operands. This operation is silent, no exception flags are set and no exceptions are thrown.
Determines if x represents a NaN. This operation is silent, no error flags are set and no exceptions are thrown.
Determines if x is normalized. This operation is silent, no error flags are set and no exceptions are thrown.
Compares two _decimal operands for equality
Checks whether a _decimal value is a power of ten. This operation is silent, no exception flags are set and no exceptions are thrown.
Determines if x represents a signaling NaN. This operation is silent, no error flags are set and no exceptions are thrown.
Determines if x is subnormal (denormalized). This operation is silent, no error flags are set and no exceptions are thrown.
Compares two _decimal operands. This operation is silent, no exception flags are set and no exceptions are thrown.
Determines if x represents the value zero. This operation is silent, no error flags are set and no exceptions are thrown.
Efficiently calculates 2 * 10n. $(BOOKTABLE,
$(TR
$(TR
Calculates the natural logarithm of logex.
Calculates log10x.
Calculates log10(x + 1).
Calculates log2x.
Calculates log2(x + 1).
Calculates loge(x + 1).
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead.
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead.
Returns the value of x rounded away from zero.
Splits x in integral and fractional part.
Undocumented in source.
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead.
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead.
Returns the next value after or before x, toward y.
Returns the previous _decimal value before x.
Gives the next power of 10 after x.
Returns the next representable _decimal value after x.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Calculates a0 + a1x + a2x2 + .. + anxn
Compute the value of xy
Compute the value of xn, where n is integral
Returns the exponent encoded into the specified _decimal value;
Express a value using another value exponent
Undocumented in source. Be warned that the author may not have intended to support it.
Calculates the remainder of the division x / y
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead. This function is similar to nearbyint, but if the rounded value is not exact it will throw InexactException
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead. This function is similar to nearbyint, but if the rounded value is not exact it will throw InexactException
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead. If the value doesn't fit in a long data type OverflowException is thrown.
Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead. If the value doesn't fit in a long data type OverflowException is thrown.
Compute the value of x1/n, where n is an integer
Returns the value of x rounded away from zero. This operation is silent, doesn't throw any exception.
Computes the inverse square root of x
Compares the exponents of two _decimal values
Multiplies elements of x using a higher precision, rounding only once at the end.
Multiplies results of xi - yi using a higher precision, rounding only once at the end.
Multiplies results of xi + yi using a higher precision, rounding only once at the end.
Determines if x is negative This operation is silent, no error flags are set and no exceptions are thrown.
Returns the sign bit of the specified value. This operation is silent, no error flags are set and no exceptions are thrown.
Returns sine of x.
Returns sine of x*π.
Calculates the hyperbolic sine of x.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source. Be warned that the author may not have intended to support it.
Computes the square root of x
Sums elements of x using a higher precision, rounding only once at the end.</br>
Sums absolute elements of x using a higher precision, rounding only once at the end.
Sums squares of elements of x using a higher precision, rounding only once at the end.
Returns tangent of x.
Returns tangent of x.
Converts x to the specified binary floating point type rounded if necessary by mode
Converts x to the specified integral type rounded if necessary by mode
Converts the specified value from internal encoding from/to densely packed decimal encoding Notes: Decimal values are represented internaly using binary integer _decimal encoding, supported by Intel (BID). This function converts the specified value to/from densely packed _decimal encoding, supported by IBM (DPD). Please note that a DPD encoded _decimal cannot be passed to a function from this module, there is no way to determine if a _decimal value is BID-encoded or DPD-encoded, all functions will assume a BID-encoding.
Converts the specified value from internal encoding from/to densely packed decimal encoding Notes: Decimal values are represented internaly using binary integer _decimal encoding, supported by Intel (BID). This function converts the specified value to/from densely packed _decimal encoding, supported by IBM (DPD). Please note that a DPD encoded _decimal cannot be passed to a function from this module, there is no way to determine if a _decimal value is BID-encoded or DPD-encoded, all functions will assume a BID-encoding.
Converts x to the specified binary floating point type rounded if necessary by mode
Converts x to the specified integral type rounded if necessary by mode
Converts the specified value to/from Microsoft currency data type;
Converts the specified value to/from Microsoft _decimal data type;
Checks the order between two _decimal values
Returns the value of x rounded up or down, depending on sign (toward zero). This operation is silent, doesn't throw any exception.
Gives the previous power of 10 before x.
Undocumented in source. Be warned that the author may not have intended to support it.
Undocumented in source.
Undocumented in source.
Undocumented in source.
Decimal floating-point computer numbering format that occupies 4, 8 or 16 bytes in computer memory.
Container for _decimal context control, provides methods to alter exception handling, manually edit error flags, adjust arithmetic precision and rounding mode
Undocumented in source.
Returns the most wide _decimal type among the specified types
Undocumented in source.
Undocumented in source.
Undocumented in source.
Undocumented in source.
Returns true if all specified types are _decimal types.
Undocumented in source.
) )
Context:
All arithmetic operations are performed using a $(U thread local context). The context is setting various environment options:
Operators:
All floating point operators are implemented. Binary operators accept as left or right side argument any decimal, integral, character or binary floating point value.
Initialization:
Creating decimal floating point values can be done in several ways:
decimal32 d = 123; decimal64 e = 12.34; decimal128 f = "24.9"; decimal32 g = 'Y'; decimal32 h = true;by assigning a binary floating point, integral, char, bool, string or character range (including strings) value:
auto d = decimal32(7500); auto e = decimal64(52.16); auto f - decimal128("199.4E-12"); auto g = decimal32('a'); auto h = decimal32(false);by using one of the available contructors. Suported type are binary floating point, integrals, chars, bool, strings or character ranges:
auto d = decimal32.nan; auto e = decimal64.PI; auto f - decimal128.infinity;using one of predefined constants:
Errors occuring in arithmetic operations using decimal values can be handled in two ways. By default, the thread local context will throw exceptions for errors considered severe (InvalidOperationException, DivisionByZeroException or OverflowException). Any other error is considered silent and the context will only set corresponding error flags (ExceptionFlags.inexact or ExceptionFlags.underflow)<br/> Most of the operations will throw InvalidOperationException if a signaling NaN is encountered, if not stated otherwise in the documentation. This behaviour is intended in order to avoid usage of unitialized variables (decimal values being by default always initialized to signaling NaN)
//these will throw: auto a = decimal32() + 12; //InvalidOperationException auto b = decimal32.min / 0; //DivisionByZeroException auto c = decimal32.max * 2; //OverflowException //these will not throw: auto d = decimal32(123456789); //inexact auto e = decimal32.min_normal / decimal32.max; //underflow
Default behaviour can be altered using DecimalControl by setting or clearing corresponding traps:
DecimalControl.disableExceptions(ExceptionFlags.overflow) //from now on OverflowException will not be thrown; DecimalControl.enableExceptions(ExceptionFlags.inexact) //from now on InexactException will be thrown
try { auto a = decimal32.min / 0; } catch (DivisionByZeroException) { //error occured }
DecimalControl.disableExceptions(ExceptionFlags.divisionByZero) DecimalControl.resetFlags(); auto a = decimal32.min / 0; if (DecimalControl.divisionByZero) { //error occured }
Values returned after an exception is thrown or after an error flag is set, depend on the current RoundingMode.
Exception | tiesToEven | tiesToAway | towardPositive | towardNegative | towardZero |
---|---|---|---|---|---|
OverflowException | +∞ | +∞ | +∞ | +max | +max |
OverflowException | -∞ | -∞ | -max | -∞ | -max |
UnderflowException | ±0.0 | ±0.0 | +min_normal * epsilon | -min_normal * epsilon | ±0.0 |
DivisionByZeroException | ±∞ | ±∞ | ±∞ | ±∞ | ±∞ |
InvalidOperationException | NaN | NaN | NaN | NaN | NaN |
InexactException does not have a specific value associated.
The subnormal exception is not implemented because it is not part of the IEEE-754-2008 standard. If an operation results in a subnormal value (absolute value is smaller than min_normal), UnderflowException is always thrown or ExceptionFlag.underflow is always set. It's better to avoid subnormal values when performing calculations, the results of the operations involving such values are not exact.
Properties:
The following properties are defined for each decimal type:
Constant | Name | decimal32 | decimal64 | decimal128 |
---|---|---|---|---|
init | initial value | signaling NaN | signaling NaN | signaling NaN |
nan | Not a Number | NaN | NaN | NaN |
infinity | positive infinity | +∞ | +∞ | +∞ |
dig | precision | 7 | 16 | 34 |
epsilon | smallest increment to the value 1 | 10$(SUPERSCRIPT-6) | 10$(SUPERSCRIPT-15) | 10$(SUPERSCRIPT-33) |
mant_dig | number of bits in mantissa | 24 | 54 | 114 |
max_10_exp | maximum int value such that 10max_10_exp is representable | 96 | 384 | 6144 |
min_10_exp | minimum int value such that 10min_10_exp is representable and normalized | -95 | -383 | -6143 |
max_2_exp | maximum int value such that 2max_2_exp is representable | 318 | 1275 | 20409 |
min_2_exp | minimum int value such that 2min_2_exp is representable and normalized | -315 | -1272 | -20406 |
max | largest representable value that's not infinity | 9.(9) * 1096 | 9.(9) * 10384 | 9.(9) * 106144 |
min_normal | smallest normalized value that's not 0 | 10-95 | 10-383 | 10-6143 |
There are common constants defined for each type. Values int the tablebelow have 34 digits of precision corresponding to decimal128 data type; for decimal64 and decimal32, they are rounded away from 0 according to their respecive precision.
auto a = decimal32.PI; auto b = decimal64.LN2; auto c = decimal128.E;
Constant | Formula | Value |
---|---|---|
E | e | 2.7182818284590452353602874713526625 |
PI | π | 3.1415926535897932384626433832795029 |
PI_2 | π/2 | 1.5707963267948966192313216916397514 |
PI_4 | π/4 | 0.7853981633974483096156608458198757 |
M_1_PI | 1/π | 0.3183098861837906715377675267450287 |
M_2_PI | 2/π | 0.6366197723675813430755350534900574 |
M_2_SQRTPI | 2/√π | 1.1283791670955125738961589031215452 |
SQRT2 | √2 | 1.4142135623730950488016887242096981 |
SQRT1_2 | √½ | 0.7071067811865475244008443621048490 |
LN10 | loge10 | 2.3025850929940456840179914546843642 |
LOG2T | log210 | 3.3219280948873623478703194294893902 |
LOG2E | log2e | 1.4426950408889634073599246810018921 |
LOG2 | log102 | 0.3010299956639811952137388947244930 |
LOG10E | log10e | 0.4342944819032518276511289189166051 |
LN2 | loge2 | 0.6931471805599453094172321214581766 |
Even all decimal operations allows the usage of binary floating point values, such mixing must be avoided; Internally, binary floating point values are converted to decimal counterparts before any operation:
float f = 1.1; decimal32 d = "2.5"; decimal32 e = d + f; //behind the scene this is roughly equivalent with e = d + decimal32(f);
It is impossible to represent binary floating point values in full decimal precision. By default, float values are converted using 9 digits of precision, double values using 17 digits of precision and real values using 21 digits of precision;
float f = 1.1; //internal representation is 1.10000002384185791015625; decimal32 d1 = d; //1.100000, 9 digits from float, but decimal32 has a 7 digits precision decimal64 d2 = d; //1.10000002000000, 9 digits from float decimal128 d3 = d; //1.10000002000000000000000000000000, 9 digits from float;
An exact conversion is possible only if the binary floating point value is an exact power of 2 and fits in the destination type precision or if it's a power of 5.
float f = 4.0; //internally represented as 1.0 * 2^^2 decimal32 d = f; //internally represented as 0.4 * 10^^1 float f = 25.0; //internally represented as 1.5625 * 2^^4 decimal32 d = f; //internally represented as 0.25 * 10^^2 float f = 2147483648; //internally represented as 1.0 * 2^^31 decimal32 d = f; //inexact, internally represented as 0.2147484 * 10^^7
Binary floating point conversion is dependent on the RoundingMode:
double d = 2.7; //internal representation is 2.7000000476837158203125; DecimalControl.rounding = RoundingMode.tiesToAway; decimal64 d1 = d; //d1 will be 2.700000047683716; DecimalControl.rounding = RoundingMode.towardZero; decimal64 d2 = d; //d2 will be 2.700000047683715;
Only Intel 80-bit reals are supported. Any other real type is cast to double before any conversion.
Copyright (c) Răzvan Ștefănescu 2018.
IEEE 754-2008 implementation of decimal floating point data types. Decimal values are represented in memory using an integral coefficient and a 10-based exponent. Implementation is based on binary integer decimal encoding, supported by Intel.
Decimal data types use the same semantics as the built-in floating point data type (NaNs, infinities, etc.), the main difference being that they use internally a 10 exponent instead of a 2 exponent.
The current implementation supports three decimal data types, as specified by IEEE 754-2008 standard. The supported types are: decimal32, decimal64 and decimal128, but they can be easily extended to other bit widths if a underlying unsigned integral type is provided.
Decimal data types are best used in financial applications because arithmetic operation results are exact.
$(DIVC quickindex, $(BOOKTABLE ,