8.1.5 Data representation - Arithmetic errors
8.1.5 Data representation - Arithmetic errors
An overflow error can occur when a calculation is run but the computer is unable to store the
answer correctly. All computers have a predefined range of values they can represent or store.
Overflow errors occur when the execution of a set of instructions return a value outside of this
range.
An error that occurs when the computer attempts to handle a number that is too large for it. Every
computer has a well-defined range of values that it can represent. If during execution of a program it
arrives at a number outside this range, it will experience an overflow error. Overflow errors are
sometimes referred to as overflow conditions.
An overflow error indicates that software attempted to write data beyond the limits of memory.
Each program has a section of memory allocated for a stack. The stack is used to store internal data
for the program and is very fast and keep track of return addressing. A program may jump to an area
that reads some data from the hard drive, then it returns from that routine to continue processing
the data. The stack keeps track of the originating address, and the program uses that for the return.
Kind of like leaving breadcrumbs to find your way back. The stack has a limited amount of storage
space. If software attempts to access an area of the stack beyond its limits, an overflow error occurs.
The stack overflow problem is not as prevalent on the newer operating systems, however, because
of the small footprint on mobile devices it can become challenging. If your operating system on your
mobile device is giving you a stack overflow error, you may have too many apps running. You may
have a virus using stack space. You could even have hardware damage that could cause a stack
overflow error message. Check your app usage and virus protection and run a memory diagnostic
app on your mobile device to see if this helps clear up your error.
An overflow error that is created by storage assignment is referenced as a data type overflow. What
this means is that a certain data type used for storing a piece of data was not large enough to hold
the data. For example, if you try to fit twelve cans of soup in a box designed to hold ten cans, two
cans will "overflow" that space. By the same token certain data types can only store numbers of a
certain size. If a data type is a single byte, and the data to be stored is greater than the unsigned
value 256, an overflow error occurs.
This type of error usually only happens with older machines trying to run modern operating systems
since the capacity of the operating system over shadows the capacity of the hardware. In other
words, you may get overflow errors when an application requests 64 bits of storage when the
program can only offer 32. The software developer is responsible for properly avoiding or handling
this type of overflow error.
Underflow
In software, underflow errors occur primarily in calculations of the floating-point data type.
For example, if the computer needs to represent the number .00004, but the data type only
supports four digits of numerical precision, only the first four zeros would be stored (.0000). If this
condition is encountered, the computer would report an underflow error.
Often, floating-point data types represent the exponent as single, signed (positive and
negative) octet. For example, the exponent of .00004 is -5, i.e., 4 x 10 -5 = .00004. A single signed byte
can store 256 possible exponents, the whole numbers ranging from -128 to 127. If the computer
tried to store the number 4 x 10-129 in that data type, the computer would report an underflow error.