Faster floating point math with Rust's new API
47 points - last Thursday at 1:43 PM
SourceGeertB
last Thursday at 7:55 PM
Signed integer addition is only associative when overflow is defined to wrap around like unsigned arithmetic. This condition is matched here, because only debug builds panic on overflow. However, it's a bit of a gray area that the article completely ignores.
Unlike C, Rust's signed arithmetic is fully specified to wrap around.
aw1621107
today at 10:58 AM
> Rust's signed arithmetic is fully specified to wrap around.
Well, kind of. It's currently documented to wrap in release mode by default, but it's just that - a default. You're free to enable overflow checks in release mode (or disable them in debug if you really like oddball configurations), and either way overflow is considered a logic error that devs shouldn't rely on (and basically can't rely on when not in control of the end binary since it's the end user who controls overflow checks).
The Rust devs are theoretically open to making signed overflow panic by default, but consider such a change unlikely unless "something materially changes" [0].
[0]: https://github.com/rust-lang/rust/issues/47739#issuecomment-...