<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Lang,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 1, 2015, at 5:57 PM, Lang Hames <<a href="mailto:lhames@gmail.com" class="">lhames@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi All,<div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><font face="monospace, monospace" class="">/* If two numbers add (exactly) to zero, IEEE 754 decrees it is a<br class="">   positive zero unless rounding to minus infinity, except that                                                    <br class="">   adding two like-signed zeroes gives that zero.  */</font><div class=""><font face="monospace, monospace" class="">if (category == fcZero && sign != addend.sign)<br class="">  sign = (rounding_mode == rmTowardNegative);</font><div class=""><br class=""></div><div class="">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.</div></div></div></div></blockquote><div><br class=""></div><div><br class=""></div><div>According to what you describe ("the comment text may not apply"), I feel that the comment might be updated as well.</div><div><br class=""></div><div>Best,</div><div><br class=""></div><div>Mehdi</div></div><br class=""></div></body></html>