digitalmars.D.learn - uint overflow behaviour
- DLearner (8/8) Sep 15 2021 Please confirm that if the addition of two uint variables
- rikki cattermole (5/5) Sep 15 2021 https://dlang.org/spec/expression.html#add_expressions
- Steven Schveighoffer (7/14) Sep 15 2021 Definition under point 7 here :
- DLearner (1/1) Sep 15 2021 Thanks for the responses.
Please confirm that if the addition of two uint variables produces a result larger than can be held in a uint: 1. This is a D-legal operation (however inadvisable!), with the D-defined result of wraparound; 2. Emphasing 1. above: the result is not undefined, or an error (by the rules of D), or simply implementation-dependant (whether by compiler or chip). Best regards
Sep 15 2021
https://dlang.org/spec/expression.html#add_expressions "7. If both operands are of integral types and an overflow or underflow occurs in the computation, wrapping will happen. For example, uint.max + 1 == uint.min, uint.min - 1 == uint.max, int.max + 1 == int.min, and int.min - 1 == int.max."
Sep 15 2021
On Wednesday, 15 September 2021 at 10:08:13 UTC, DLearner wrote:Please confirm that if the addition of two uint variables produces a result larger than can be held in a uint: 1. This is a D-legal operation (however inadvisable!), with the D-defined result of wraparound;Definition under point 7 here : https://dlang.org/spec/expression.html#add_expressions And I wouldn’t say inadvisable. It’s defined and if you have a good reason to allow that, then you can do that.2. Emphasing 1. above: the result is not undefined, or an error (by the rules of D), or simply implementation-dependant (whether by compiler or chip).Yes -Steve
Sep 15 2021