rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
694 stars 131 forks source link

Fix checked operations documentation. #332

Closed ocstl closed 3 weeks ago

ocstl commented 1 month ago

Closes #13 . Remove the implication that wrapping is the default behaviour.

The documentation mentions "underflow" (for example, in CheckedSub), which I left as is. But Rust's documentation tends to refer to "overflow" exclusively (see i32::checked_sub).

I've recently been made aware that overflow is probably the correct term in both cases for integers (positive and negative), while underflow is strictly reserved for floating points. Either way, it's not a big deal and I'm not bothered by it, as the meaning is clear, but I thought I should mention it.

cuviper commented 1 month ago

Let's change "underflow" -- the reference calls it "overflow" for results less than the minimum: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow

... and "underflow" isn't found in the reference at all!

ocstl commented 1 month ago

I guess the reference settles that!

I also missed the CheckedEuclid methods in the first commit, but they are now fixed as well.

cuviper commented 3 weeks ago

Thanks!