<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jul 23, 2010, at 7:20 AM, Steffen Geißinger wrote:</div><blockquote type="cite"><div><font color="#000000">i need to check if an overflow of an floating-point arithmetic operation occured.</font></div>
<div><font color="#000000">Currently I'm doing something like this (for addition):</font></div>
<div><font size="2"><font color="#000000" size="2"></font></font> </div>
<div><font size="2"><font color="#000000" size="2">(LHS > 0 && RHS > 0 && sum <= 0)  || (LHS < 0 && RHS < 0 && sum >= 0)</font></font></div></blockquote><div><br></div>IEEE floating-point doesn't overflow like this;  if the magnitude of a result is too</div><div>large to represent, it becomes an infinity rather than wrapping around like integer</div><div>arithmetic.  You want to check whether the result is infinite.</div><div><br></div><div>I think the easiest way of doing that is to check whether (x - x) != (x - x).</div><div><br></div><div>John.</div></body></html>