A 128-bit fixed-length Decimal value in the ANSI SQL Numeric semantics, representing unscaledValue / 10**scale where scale is 0 or positive.
This class is similar to {@link java.math.BigDecimal}, but a few things differ to conform to the SQL Numeric semantics.
Scale of this object is specified by the user, not automatically determined like {@link java.math.BigDecimal}. This means that underflow is possible depending on the scale. {@link java.math.BigDecimal} controls roundingbehaviors by MathContext, possibly throwing errors. But, underflow is NOT an error in ANSI SQL Numeric. "CAST(0.000000000....0001 AS DECIMAL(38,1))" is "0.0" without an error.
Because this object is fixed-length, overflow is also possible. Overflow IS an error in ANSI SQL Numeric. "CAST(10000 AS DECIMAL(38,38))" throws overflow error.
Each arithmetic operator takes scale as a parameter to control its behavior. It's user's (or query optimizer's) responsibility to give an appropriate scale parameter.
Finally, this class performs MUCH faster than java.math.BigDecimal for a few reasons. Its behavior is simple because of the designs above. This class is fixed-length without array expansion and re-allocation. This class is mutable, allowing reuse of the same object without re-allocation. This class and {@link UnsignedInt128} are designed such that minimal heap-objectallocations are required for most operations. The only exception is division. Even this class requires a few object allocations for division, though much fewer than BigDecimal.
|
|