[LLVMdev] [PATCH] [ADT] APFloat - Fix sign handling for FMA results that truncate to zero.

Lang Hames lhames at gmail.com
Thu Jan 1 17:57:11 PST 2015


Hi All,

APFloat::fusedMultiplyAdd currently computes the wrong signed zero when
small negative results are truncated back to zero in standard precision.
The following snippet handles the signedness in fusedMultiplyAdd:

/* If two numbers add (exactly) to zero, IEEE 754 decrees it is a
   positive zero unless rounding to minus infinity, except that

   adding two like-signed zeroes gives that zero.  */
if (category == fcZero && sign != addend.sign)
  sign = (rounding_mode == rmTowardNegative);

The test "category == fcZero" tells us that the result was zero after
rounding back down to standard precision, but since the addition is carried
out in extended precision this doesn't guarantee that the result of the
addition was exactly zero (so the comment text may not apply). The attached
patch adds a check for underflow during truncation which ensures the
correct signedness of the result.

Cheers,
Lang.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150101/6b879295/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: APFloat_FMA_truncated_zero_sign.patch
Type: application/octet-stream
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150101/6b879295/attachment.obj>


More information about the llvm-dev mailing list