Feature/checked wrapping ops#24
Conversation
it'd seem these can be defined as helpers in add/sub and so use the intrinsics when available. So why make them pure only? oh nvm. It's so they can be called using |
Yeah, that sounds totally reasonable and I've thought about that at first. Like, if raising* is basically just overflowing* with an added if-else branch, it should be moved to composite where all the other sugar ops live. I'm seeing problems with that:
Yeah, I'm basically following my own contributor's guide and existing architecture which separates dispatching from implementations and suggests adding the pure Nim implementation first. |
|
I did some experimentation with the lib structure but ended up following the current architecture. For raisingAdd and raisingSub, I've added implementations with GCC intrinsics similarly to saturating*. In local benchmarks, they perform better, as expected. |
Added:
All ops are implemented only in pure Nim so far and use overflowing ops internally.
The point of raising ops is that they are guaranteed to raise OverflowDefect on signed and unsinged ints no matter what the compilation flags are. This distinguishes them from
+and-in the stdlib.The point of wrapping ops is that they are guaranteed to wrap for signed and unsigned ints but unlike overflowing ops they don't return an overflow flag.