Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add saturating_* and wrapping_* API definitons to CheckedArithmeticCore #9

Closed
kimikage opened this issue Sep 18, 2020 · 2 comments
Closed

Comments

@kimikage
Copy link
Collaborator

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.

@kimikage
Copy link
Collaborator Author

My implementation of the FixedPoint saturating operations means that we have already implemented most of the Integer saturating operations. In other words, they are worth reusing.
Therefore, I think the implementation of saturating operations for Integers may exist in the CheckedArithmeticCore. Furthermore, I believe that LLVM's saturating instructions are worthy of being supported by Julia.

@kimikage
Copy link
Collaborator Author

Additional functionality will be added in OverflowContexts.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant