Overflow Detection

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
Dear friends,

I read about overflow detection. But one thing that I do not understand is that what is the purpose of classifying the arithmetic operation to either overflow exist or not ?

Please have a look at the image attached :)

If overflow means that the output is invalid ?

For example, +5 + 3 = +8 (expected)

but in actual it gave us 1000, which is -8 in 2s complement. So means the operation is not valid ?

Thanks !
 

Attachments

Papabravo

Joined Feb 24, 2006
14,678
In a 2's complement representation an overflow is the result of arithmetic operations exceeding the upper or lower bounds of the representation range. In your example a 4-bit quantity can represent any number in the range [-8,...,+7]. Any result outside that range is an overflow. If you look at the datasheet for a processor with an overflow condition code, you will see a Boolean equation for overflow. IIRC it involves the sign of the result and the signs of the operands.
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
In a 2's complement representation an overflow is the result of arithmetic operations exceeding the upper or lower bounds of the representation range. In your example a 4-bit quantity can represent any number in the range [-8,...,+7]. Any result outside that range is an overflow. If you look at the datasheet for a processor with an overflow condition code, you will see a Boolean equation for overflow. IIRC it involves the sign of the result and the signs of the operands.
So does my example shown is overflow case ? why is that so ?

Thanks !
 

Papabravo

Joined Feb 24, 2006
14,678
You have to pick a representation. The 4-bit quantities are either unsigned or signed 2's complement or they could be signed 1s complement or any other variety of representation. Once we know what is the intended representation we can tell what "overflow" means.

In your first example you have an "expectation" that you can represent +8 as the sum of +3 and +5. This is nonsense since +8 is not a representable number in 2's complement signed notation.
 

WBahn

Joined Mar 31, 2012
26,301
Dear friends,

I read about overflow detection. But one thing that I do not understand is that what is the purpose of classifying the arithmetic operation to either overflow exist or not ?

Please have a look at the image attached :)

If overflow means that the output is invalid ?

For example, +5 + 3 = +8 (expected)

but in actual it gave us 1000, which is -8 in 2s complement. So means the operation is not valid ?

Thanks !
Using 4-bit 2-complement representation, 5 + 3 = -8, right?

If that a correct result (in terms of normal arithmetic)?

If the answer is no, then an overflow has occured, otherwise an overlow hasn't occured.

It's really that simple.
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
Using 4-bit 2-complement representation, 5 + 3 = -8, right?

If that a correct result (in terms of normal arithmetic)?

If the answer is no, then an overflow has occured, otherwise an overlow hasn't occured.

It's really that simple.
If overflow occurs, means we do not need to care for the result or the output ? We can ignore ?

Thanks !
 

shteii01

Joined Feb 19, 2010
4,644
If overflow occurs, means we do not need to care for the result or the output ? We can ignore ?

Thanks !
If overflow occurs, then the number that you just calculated will mess up some other future calculation, which in turn can result in nothing or a nuclear disaster if the system that had the overflow is part of nuclear reactor control system.

You are the designer. If overflow is ok with you, then it is ok with us. If it kills you, we don't care.
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
If overflow occurs, then the number that you just calculated will mess up some other future calculation, which in turn can result in nothing or a nuclear disaster if the system that had the overflow is part of nuclear reactor control system.

You are the designer. If overflow is ok with you, then it is ok with us. If it kills you, we don't care.
Okay!

Noted and thanks ! :)

So it is better to ignore the output that overflow :D
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
How did you arrive at that conclusion?

If an overflow occurred and the result is incorrect then you have a problem.
In my case of study which I am currently learning digital electronics theory. So we are taught to ignore the output if overflows happen and we are not taught on how to fix that yet.

Thanks :)
 

WBahn

Joined Mar 31, 2012
26,301
If overflow occurs, means we do not need to care for the result or the output ? We can ignore ?

Thanks !
What do you mean by "ignore"? Just pretend nothing happened and proceed on with the calculations?

What is the most appropriate thing to do depends on the application in question and what the consequences are of the various options.
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
What do you mean by "ignore"? Just pretend nothing happened and proceed on with the calculations?

What is the most appropriate thing to do depends on the application in question and what the consequences are of the various options.
I mean just stated there output is invalid.

Thanks !
 

MrChips

Joined Oct 2, 2009
22,092
No. There can be serious consequences depending on the application if an overflow occurs.

One approach is to ensure that an overflow never occurs.
 
Top