cedar-policy / cedar-go

Golang implementation of the Cedar Policy Language
Apache License 2.0
83 stars 9 forks source link

Create a safer interface for the Decimal type` #49

Closed patjakdev closed 2 weeks ago

patjakdev commented 2 weeks ago

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 to Decimal, which is required in order to allow for the evaluation of the decimal comparison operators.

Breaking changes: