3 ms·
For IEEE floating point, there is NaN and +/-Infinity which are raised when dividing by zero: http://grouper.ieee.org/groups/754/faq.html#exceptions http://grou
by haberman 12y ago
For IEEE floating point, there is NaN and +/-Infinity which are raised when dividing by zero: http://grouper.ieee.org/groups/754/faq.html#exceptions http://grouper.ieee.org/groups/754/faq.html#exceptions
For integers that don't have NaN/infinity values the options are less clear. Note that languages with two's complement fixed width signed types like int32 have the same problem with INT32_MIN / -1, since the result is not representable as an int32.
- thegeomaster 12y agoYeah, but they usually just say that the result is undefined. At least that's what C and C++ do. And it's useful for optimizers, because they can assume more about basic arithmetic in signed types and do some neat tricks.
- haberman 12y ago> Yeah, but they usually just say that the result is undefined. Just to clarify, I think you're talking about the INT_MIN / -1 case? I think that floating-point division by zero is defined in C and C++.
- thegeomaster 12y agoYes, I was talking about the signed integer overflow. Floating point division by zero is of course defined in C/C++, as per IEEE 754.
- logicallee 12y agoCalling it undefned is a cute meta-exception, but the compiler (or runtime) still does something when hitting that code.
- klodolph 12y agoYeah, the compiler typically assumes it works, and encodes assumptions that it does work into the surrounding code. On some systems you will get SIGFPE. On other systems, the result is something defined like 0. On some systems, the result is whatever happened to be in some register or whatever.
- pjmlp 12y ago> At least that's what C and C++ do. And it's useful for optimizers, And for security exploits.