This PR adds safe constructors for Decimal, allowing callers to pass an integer, a floating point value, or a decimal value as expressed via a significant and exponent.
Overflow and underflow are checked to ensure that invalid values can't be passed. However, care must be taken when using NewDecimalFromFloat() as values with a high number of significant digits can suffer from precision loss.
A Cmp() method has also been added to Decimal, which is required in order to allow for the evaluation of the decimal comparison operators.
Breaking changes:
The internal representation of Decimal as an int64 has been made private to allow future flexibility in implementation.
The UnsafeDecimal() constructor has been removed. Callers should use the new, safe constructors instead.
The DecimalPrecision constant has been made private
Issue #, if available: None
Description of changes:
This PR adds safe constructors for
Decimal
, allowing callers to pass an integer, a floating point value, or a decimal value as expressed via a significant and exponent.Overflow and underflow are checked to ensure that invalid values can't be passed. However, care must be taken when using
NewDecimalFromFloat()
as values with a high number of significant digits can suffer from precision loss.A
Cmp()
method has also been added toDecimal
, which is required in order to allow for the evaluation of the decimal comparison operators.Breaking changes:
int64
has been made private to allow future flexibility in implementation.UnsafeDecimal()
constructor has been removed. Callers should use the new, safe constructors instead.