Re:Fast midpoint between two integers without overflow
by ithinkso on Wednesday December 07, 2022 @10:51AM
(#33895735)
Isn't uint8 exactly what your 'integer[modulo 256]' is? And for unbounded you do need bignum and dynamic allocation so I'm not sure I see any benefits to explicitely fine-graining the range instead of using machine word at all times and bignums when needed
[ Parent
| on HN ]
Re:Fast midpoint between two integers without overflow
by wongarsu on Wednesday December 07, 2022 @12:25PM
(#33897208)
> Isn't uint8 exactly what your 'integer[modulo 256]' is
In c/c++ it is. Obviously some other languages would disagree.
I think a better example of what GP is thinking about is Rust's approach, where overflowing an u8 panics (in debug builds), but you can do x.wrapping_add(y), x.saturating_add(y), x.checked_add(y) etc., depending on what you want to happen when the operation overflows.