Integer overflow: Difference between revisions

Content deleted Content added
Throowa (talk | contribs)
added carry (arithmetic) in See also
Explicit propagation: needs a source that any processor has a special value for integer overflow, rather than floating-point overflow (which is in any case Inf, not NaN)
Line 99:
 
Handling possible overflow of a calculation may sometimes present a choice between performing a check ''before'' a calculation (to determine whether or not overflow is going to occur), or ''after'' it (to consider whether or not it likely occurred based on the resulting value). Since some implementations might generate a [[interrupt|trap]] condition on integer overflow, the most portable programs test in advance of performing the operation that might overflow.
 
===Explicit propagation===
If a value is too large to be stored it can be assigned a special value indicating that overflow has occurred and then have all successive operations return this flag value. Such values are sometimes referred to as [[NaN]], for "not a number". This is useful so that the problem can be checked once at the end of a long calculation rather than after each step. This is often supported in floating-point hardware called [[floating point unit|FPUs]].
 
===Programming language support===