[LLVMdev] Floating-Point Overflow check

John McCall rjmccall at apple.com
Fri Jul 23 10:36:37 PDT 2010


On Jul 23, 2010, at 7:20 AM, Steffen Gei├činger wrote:
> i need to check if an overflow of an floating-point arithmetic operation occured.
> Currently I'm doing something like this (for addition):
>  
> (LHS > 0 && RHS > 0 && sum <= 0)  || (LHS < 0 && RHS < 0 && sum >= 0)

IEEE floating-point doesn't overflow like this;  if the magnitude of a result is too
large to represent, it becomes an infinity rather than wrapping around like integer
arithmetic.  You want to check whether the result is infinite.

I think the easiest way of doing that is to check whether (x - x) != (x - x).

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100723/2f50019d/attachment.html>


More information about the llvm-dev mailing list