[cfe-dev] floating point division by 0.0 and -ftrapv

Jeff Walden jwalden+clang at mit.edu
Fri Dec 23 19:00:47 PST 2011


On 12/23/2011 12:56 PM, Sean McBride wrote:
> I know that integer div by 0 is undefined behaviour, but is fp div by zero also undefined?

C++98 5.6 Multiplicative operators [expr.mul]p4 says , "If the second operand of / or % is zero the behavior is undefined".  It's the same in C++11 N3242.  Floating point division is not distinguished from integral division, and as floating point operations' precision and such aren't defined, it's not surprising (although it's certainly unfortunate at times) that division by 0.0f or 0.0d isn't distinguished.

Jeff



More information about the cfe-dev mailing list