Hacker News new | past | comments | ask | show | jobs | submit login

Rust has all these arithmetic modes on its integer primitives.

The operators, such as +, panic on overflow in debug buids and wrap as two's complement in release builds.

As methods you get:

1) Two's complement wrapping (even in debug builds)

2) Saturation

3) Overflow checking (these return Option<T>




> 1) Two's complement wrapping (even in debug builds)

As it's a relatively common need, there's also a wrapper struct for this one: https://doc.rust-lang.org/core/num/struct.Wrapping.html




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: