How to define underflow for an implementation(IEEE754) which support subnormal numbers?

1k views Asked by At

Recently I am confusing about the definition of underflow of IEEE754 standard. We know that if an implementation doesn't support subnormal numbers, then the smallest number that can be represented is MinNorm = 1.0 * 2^-126. For any operation, if its result is smaller than MinNorm, will be regard as underflow. But if an implementation support subnormal numbers, then the smallest number that can be represented is MinSubnorm = 1.0 * 2^-149. Now here is the question: if a operation's result is smaller than MinNorm, if it's underflow? How about smaller than MinSubnorm ?

And now I am working on the implementation of a FPU which support the subnormal numbers. We assume that the result before rounding is strictly between -MinNorm and +MinNorm and it will also be smaller than MinNorm after rounding(representable using subnormal numbers). What would I regard it as? underflow or non-underflow? if i need to set the status bit of underflow?

I have found some imformation online, but opinons diverge as follow:

  1. http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/underflow.html Underflow occurs when you perform an operation that's smaller than the smallest magnitude non-zero number. In IEEE 754 single precision this means a value which has has magnitude (i.e., absolute value) less than 1.0 x 2-149.

  2. http://en.wikipedia.org/wiki/Arithmetic_underflow Arithmetic underflow can occur when the true result of a floating point operation is smaller in magnitude (that is, closer to zero) than the smallest value representable as a normal floating point number in the target datatype

2

There are 2 answers

1
Simon Byrne On BEST ANSWER

The IEEE754 2008 standard (ยง7.5) defines that the underflow exception shall be signalled when the result is

  1. non-zero, and
  2. strictly between -MinNorm and +MinNorm: it leaves it up to implementation as to whether this is before or after rounding, so you could have values just below minNorm that get rounded up and don't signal the exception.

So in this case, wikipedia is correct.

UPDATE: The default rules are that you DO set the status bit, unless the result is exact. e.g if a subnormal result is obtained from an addition or subtraction, then no rounding needs to occur, so you won't set the underflow status bit. On the other hand, if you have a number 1.0001 and you multiply it by 2^-149, then the result can't be exactly represented, and will be rounded to 2^-149, so you would set the underflow and inexact status bits.

1
thus spake a.k. On

IEEE 754 supports gradual underflow. It begins when a number is smaller than the smallest normal floating point number, as described by your second quote, and ends with total underflow to zero, as described by your first.