What is Underflow and overflow??
Show older comments
Like the title said what is underflow and overflow? if 1000^-500 is this underflow? what about -1000^500?? underflow too??
Answers (1)
Walter Roberson
on 13 Jun 2015
0 votes
http://www.mathworks.com/help/matlab/matlab_prog/floating-point-numbers.html and scan down to "Largest and smallest"
8 Comments
Victor Seaw
on 13 Jun 2015
Walter Roberson
on 13 Jun 2015
Underflow for double precision is smaller absolute value than 2.22507e-308, overflow is larger absolute value than 1.79769e+308. Underflow will create a 0. Overflow will create an infinity.
Note: for the unsigned integer classes, attempting to store a negative number results in a 0, and attempting to store a value larger than the largest integer for that number of bits "saturates" at the largest integer value, not an infinity.
Victor Seaw
on 13 Jun 2015
Walter Roberson
on 13 Jun 2015
For data of "double" data type:
If the value is less than -1.79769e+308 it will become -inf
If the value is between -2.22507e-308 and +2.22507e-308 it will become 0.
If the value is greater than +1.79769e+308 it will become +inf
Victor Seaw
on 13 Jun 2015
Walter Roberson
on 13 Jun 2015
The rules are similar for data of type "single" but the values change and are documented on the link I posted above.
There are integer data types as well. They fall into two classes: unsigned integer and signed integer. Signed integer classes can store negative numbers, but unsigned integer classes cannot store negative numbers. There is no inf for integer classes. A number that is too small (more negative) than can be represented in the integer class will be converted to the smallest number that is representable in the integer class. A number that is too large for the integer class will be converted to the largest number that is representable in the integer class.
For example, 16 bit signed integers, the smallest representable number is -32768 and the largest representable number is +32767. Numbers such as -40000 that are more negative than the -32768 will be converted to -32768. Numbers that are more positive than the largest representable number will be converted to +32767.
For example, 16 bit unsigned integers, the smallest representable number is 0 and the largest representable number is +65535. Numbers such as -40000 that are more negative than the 0 will be converted to 0. Numbers that are more positive than the largest will be converted to +65535.
Victor Seaw
on 13 Jun 2015
Walter Roberson
on 13 Jun 2015
The conventions about what "underflow" and "overflow" mean are different between integers and floating point numbers.
For floating point numbers, "underflow" is said to occur when a value is too close to 0 to differentiate it from 0.
For integer class numbers, "underflow" is said to occur when the value would be less than the minimum integer representable in that class.
In every floating point system that I know of, a value that is too close to 0 is made into 0 (though there may be provisions to signal an exception when it happens.)
In the majority of integer representations, a value that is too negative gets converted into a positive value, and a value that is too positive gets converted into a negative value; such systems are said to "wrap around". Those systems are much more common than the way MATLAB does it. An example would be that with 16 bit signed integers, subtracting 1 from -32768 would give you +32767 in those systems, and adding 1 to +32767 would give you -32768.
... Since you asked about underflow and overflow.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!