What is Underflow and overflow??

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
Walter Roberson on 13 Jun 2015

8 Comments

so underflow is when is -inf and overflow is inf?
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.
Ill say what out what i understand from what i read. So if the answer is lesser than 2.22e-308( its a close to zero as it can be ) its a underflow and if the value is more than 1.80e308 ( since the value is almost to inf ) it will be a overflow. However what about -inf? which category it fall into? Im sorry i don't understand the 'Note' section.
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
If the value is less than -1.79769e+308 it will become -inf [Overflow]
If the value is between -2.22507e-308 and +2.22507e-308 it will become 0. [Underflow]
If the value is greater than +1.79769e+308 it will become +inf [Overflow]
like this?? Sorry for all these. My homework require me to classified numbers(inf/-inf/0) into overflow or underflow
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.
ehm okay but what does these gotta do with underflow/overflow?? Im really sorry im a very slow learner
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.

Sign in to comment.

Asked:

on 13 Jun 2015

Commented:

on 13 Jun 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!