JuliaMath / JuliaMath/FixedPointDecimals.jl
Introduce a toggle for making inexact arithmetic throw
- Dominant language
- Julia
- Stars
- 37
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
Operations like `*` or `\` can be lossy because they can cause the number of fractional digits to exceed the precision of the FD type, e.g.:
```julia
julia> FixedDecimal{Int,2}(1.11) * FixedDecimal{Int,2}(1.11)
FixedDecimal{Int64,2}(1.23)
```
while the precise answer would be `FixedDecimal{Int64,4}(1.2321)`. During this computation, we materialize the result in full precision and then use `_round_to_nearest` to round to fix the FD type. It would be good to have the option to make such lossy operations throw an error by making the `_round_to_nearest` use `RoundThrows` rounding mode so that the user can be sure that their e.g. financial reports are exact. We already support `RoundThrows` for parsing.
This could be a global toggle in the style of [ToggleableAsserts.jl ](https://github.com/MasonProtter/ToggleableAsserts.jl/blob/master/src/ToggleableAsserts.jl).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.