@@ -10,20 +10,27 @@ or erroneous.
1010##### Integer overflow
1111
1212If a program contains arithmetic overflow, the programmer has made an
13- error.
13+ error. In the following discussion, we maintain a distinction between
14+ arithmetic overflow and wrapping arithmetic. The first is erroneous,
15+ while the second is intentional.
1416
1517When the programmer has enabled ` debug_assert! ` assertions (for
16- example, by enabling a non-optimized build), the compiler will insert
17- dynamic checks that ` panic ` on overflow. Other kinds of builds may
18- result in silently wrapped values on overflow.
18+ example, by enabling a non-optimized build), implementations must
19+ insert dynamic checks that ` panic ` on overflow. Other kinds of builds
20+ may result in ` panics ` or silently wrapped values on overflow, at the
21+ implementation's discretion.
22+
23+ In the case of implicitly-wrapped overflow, implementations must
24+ provide well-defined (even if still considered erroneous) results by
25+ using two's complement overflow conventions.
1926
2027The integral types provide inherent methods to allow programmers
21- explicitly to perform wrapping arithmetic. For example, (using UFCS)
22- ` i32::wrapping_add ` provides two's complement, wrapping addition, as
23- in ` a + b ` in the C programming language.
28+ explicitly to perform wrapping arithmetic. For example,
29+ ` i32::wrapping_add ` provides two's complement, wrapping addition.
2430
2531The standard library also provides a ` Wrapping<T> ` newtype which
26- overloads arithmetic operators by way of the ` WrappingOps ` trait.
32+ ensures all standard arithmetic operations for ` T ` have wrapping
33+ semantics.
2734
2835See [ RFC 560] for error conditions, rationale, and more details about
2936integer overflow.
0 commit comments