diff --git a/Language/Variables/Data Types/int.adoc b/Language/Variables/Data Types/int.adoc index df7ea51e9..b9c42dc79 100644 --- a/Language/Variables/Data Types/int.adoc +++ b/Language/Variables/Data Types/int.adoc @@ -53,17 +53,8 @@ The Arduino takes care of dealing with negative numbers for you, so that arithme [float] === Notes and Warnings -When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacity, note that this happens in both directions. -[source,arduino] ----- -int x; - x = -32768; - x = x - 1; // x now contains 32,767 - rolls over in neg. direction +When signed variables are made to exceed their maximum or minimum capacity they _overflow_. The result of an overflow is unpredictable so this should be avoided. A typical symptom of an overflow is the variable "rolling over" from its maximum capacity to its minimum or vice versa, but this is not always the case. If you want this behavior, use link:unsignedInt{ext-relative}[unsigned int]. - x = 32767; - x = x + 1; // x now contains -32,768 - rolls over - ----- [%hardbreaks] [float] diff --git a/Language/Variables/Data Types/unsignedInt.adoc b/Language/Variables/Data Types/unsignedInt.adoc index 87ac48a6d..1a6bc9400 100644 --- a/Language/Variables/Data Types/unsignedInt.adoc +++ b/Language/Variables/Data Types/unsignedInt.adoc @@ -46,11 +46,11 @@ The difference between unsigned ints and (signed) ints, lies in the way the high [float] === Notes and Warnings -When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions +When unsigned variables are made to exceed their maximum capacity they "roll over" back to 0, and also the other way around: [source,arduino] ---- -unsigned int x +unsigned int x; x = 0; x = x - 1; // x now contains 65535 - rolls over in neg direction x = x + 1; // x now contains 0 - rolls over