-
Notifications
You must be signed in to change notification settings - Fork 4
Description
As mentioned in https://discourse.julialang.org/t/rfc-what-should-the-arithmetic-within-the-fixedpointnumbers-be/46697, I would like to add the definitions of arithmetic operations such as saturating_add and wrapping_sub, currently defined in FixedPointNumbers#master, to the CheckedArithmeticCore.
They are "unchecked", so it is a self-contradiction that they join the CheckedArithmetic. 😅 However, I think it's reasonable to assume that they just provide the opt-out functionality.
This allows you to call them as CheckedArithmeticCore.wrapping_* (essentially a re-export to CheckedArithmetic.wrapping_*) regardless of where they are implemented. That is, we can support @wrapping and @saturating in the same way as @checked. As you may have noticed, `replace_checked!' was already generalized. 😝
https://github.com/JuliaMath/CheckedArithmetic.jl/pull/8/files#diff-716c7804fe3fca686524a1eae34996ea
While there's nothing hard about defining the APIs itself, there are a few challenges that need to be overcome to make @saturating and@wrapping practical. One is that, as mentioned in #7, the fallback implementations are required. And related to that, there is no systematic implementation of Integer "saturating" operations in Base.