PaesslerAG / gval

Expression evaluation in golang
BSD 3-Clause "New" or "Revised" License
713 stars 83 forks source link

Add DecimalArithmetic language #71

Closed machship-mm closed 2 years ago

machship-mm commented 2 years ago

This pull request will merge in the handling of DecimalArithmetic.

Decimal (base10 numbers) arithmetic is different to floating point (base2 numbers) arithmetic, and in use cases that involve money, it's imperative that the user is given the option to have any arithmetic calculations made using fixed-point decimal numbers rather than floating point.

DecimalArithmetic is added and used strictly as an optional use case (not added to the full() language set). It is not used unless one specifies its use.

Use can be specified by calling the DecimalArithmetic language directly and evaluation expressions against that language. DecimalArithmetic overrides the default handling for scanner.Int and scanner.Float to use parseDecimal and then all arithmetic is run against the decimal.Decimal from the widely used shopspring/decimal repository.

Tests and Benchmark Tests have been added.

This pull request fixes #70.