[cfe-dev] floating point division by 0.0 and -ftrapv
sean at rogue-research.com
Wed Jan 25 10:04:53 PST 2012
On Sat, 31 Dec 2011 20:19:36 -0800, John McCall said:
>>> 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.
>Our intent is to implement IEEE floating point semantics. Giving FP-
>divide-by-zero undefined behavior would be inconsistent with that. LLVM
>does not optimize based on this, and -ftrapv should not trap on it.
>This can be considered a case of intentionally defining the behavior of
>something left undefined by the standard.
I have created this bug:
Sean McBride, B. Eng sean at rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
More information about the cfe-dev