[LLVMdev] Floating-Point Overflow check

me22 me22.ca at gmail.com
Fri Jul 23 10:37:06 PDT 2010


On 23 July 2010 07:20, Steffen Geißinger
<steffen.geissinger at googlemail.com> 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)
>

Two things:
1) Have you tried adding 2 float-max values together to see what you
get?  It's not a negative (on most platforms, at least).  IEEE
floating-point has "infinities".
2) That method doesn't even work for integers, since overflow in
signed addition is undefined, and compilers will, correctly, remove
the check as impossible.




More information about the llvm-dev mailing list