Talk:Overflow Flag

From IntelliWiki

Overflow vs. underflow. There are two different definitions of overflow and underflow: The magnitude of the number got too big/small to fit in the register, or the numeric value exceeded the maximum/minimum values representable in the register. I prefer the former, since it is consistent with how floating point describes numeric conditions. Here's an example of the difference:

Suppose I put the signed number 0x7FFF in a 16-bit register and add 1. The result is 0x8000. That's overflow, by both senses. If I put 0x8000 and subtract 1, the result's 0x7FFF. That's also overflow by the first definition—I need more bits to the left of the binary-point to correctly express the result—but underflow by the second definition—the number got too negative and it wrapped around.

Underflow in the first sense happens when the result is too small to be represented in the current precision. Suppose I start with the number 4, and I divide by 2 with integer division. The result's 2. So far, so good. I divide by 2 again. The result's 1--still ok. Now I divide by 2 once more. The result's 0.5. Oops: I'm doing integer division, and so I can't represent the result. This is underflow in the sense of the first definition. In floating point, underflow happens when the exponent gets too negative--you need more bits to the right of the binary point to correctly express the number.

The CP1610 provides nothing to detect underflow in the floating-point sense, but it also doesn't ever bring up the term in any of its documentation. Thus, I suggest we just stick to the term "Overflow." Thoughts? --Mr z 19:51, 11 Jan 2005 (EST)