[cfe-dev] cfe-dev Digest, Vol 54, Issue 82

Fred J. Tydeman tydeman at tybor.com
Sat Dec 24 07:56:44 PST 2011


On Sat, 24 Dec 2011 09:01:15 -0600 cfe-dev-request at cs.uiuc.edu wrote:
>
>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.


However, if the floating-point unit conforms to IEEE-754 (most chips these days do), 
then fp div by zero is well defined by IEEE-754.  C99 and C11 (via annex F) say that
'/' in C is '/' in IEEE-754 and send the reader of the standard to IEEE-754 to find
the semantics of '/'.


---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (775) 358-9748      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.




More information about the cfe-dev mailing list