Content deleted Content added
Jerryobject (talk | contribs) Image: update > File:. WP:LINKs: updates, adds, needless underscores > spaces. Cut needless carriage returns in: paragraphs, WP:REFerence WP:CITations. Small WP:EoS WP:TERSE WP:COPYEDITs. WP:REF WP:CIT parameters: respaces, reorders, author > last + first. MOS:FIRSTABBReviations define before WP:ABBRs in parentheses. Avoidable spaced WP:SLASH > WP:NDASH. |
Jerryobject (talk | contribs) m Cut needless carriage return whitespace characters in sections: standardize, aid edits via mobile devices. |
||
Line 16:
== Origin ==
The [[register width]] of a processor determines the range of values that can be represented in its registers. Though the vast majority of computers can perform multiple-precision arithmetic on operands in memory, allowing numbers to be arbitrarily long and overflow to be avoided, the register width limits the sizes of numbers that can be operated on (e.g., added or subtracted) using a single [[Instruction set architecture#Instructions|instruction]] per operation. Typical [[Binary numeral system|binary]] register widths for unsigned integers include:
* [[4-bit computing|4-bit]]: maximum representable value 2<sup>4</sup> - 1 = 15
* [[8-bit computing|8-bit]]: maximum representable value 2<sup>8</sup> − 1 = 255
Line 41 ⟶ 40:
==Definition variations and ambiguity==
For an unsigned type, when the ideal result of an operation is outside the type's representable range and the returned result is obtained by wrapping, then this event is commonly defined as an overflow. In contrast, the C11 standard defines that this event is not an overflow and states "a computation involving unsigned operands can never overflow."<ref name="auto"/>
Line 53 ⟶ 51:
==Inconsistent behavior==
The behavior on occurrence of overflow may not be consistent in all circumstances. For example, in the language [[Rust (programming language)|Rust]], while functionality ''is'' provided to give users choice and control, the behavior for basic use of mathematic operators is naturally fixed; however, this fixed behavior differs between a program built in 'debug' mode and one built in 'release' mode.<ref>{{Cite web |title=Operator expressions - The Rust Reference |url=https://doc.rust-lang.org/stable/reference/expressions/operator-expr.html#overflow |website=Rust-lang.org |access-date=2021-02-12}}</ref> In C, unsigned integer overflow is defined to wrap around, while signed integer overflow causes [[undefined behavior]].
==Methods to address integer overflow problems==
{| class="wikitable" style="float:right; margin-left:1em; margin-right:0; width:30%;"
|+ Integer overflow handling in various programming languages
Line 92 ⟶ 88:
===Detection===
Run-time overflow detection implementation <code>UBSan</code> is available for [[C compiler]]s.
|