It's all in the Title. For example if the addition of two floats results in INF, does it generate an undefined behavior? or is this avoided in IEEE float implementation?
Asked
Active
Viewed 177 times
0
-
6Undefined behaviour seems to be the flavour of the day. – devnull Jul 11 '13 at 10:00
-
1possible duplicate of [When a float variable goes out of the float limits, what happens?](http://stackoverflow.com/questions/17588419/when-a-float-variable-goes-out-of-the-float-limits-what-happens) – devnull Jul 11 '13 at 10:01
-
@devnull I lol'd so hard. At least this question is syntactically correct. – gifnoc-gkp Jul 11 '13 at 10:03
1 Answers
4
No. There is no undefined behavior in IEEE-754 arithmetic. The result is defined to be infinity for the example in question, and it is defined to set a flag indicating that overflow occurred.
The only room for undefined behavior is if the platform in question doesn't adhere to IEEE-754. (C and C++ do not require that floating-point arithmetic follows IEEE-754)

Stephen Canon
- 103,815
- 19
- 183
- 269
-
-
1The Overflow flag indicates overflow. In most implementations, this flag is implemented as a bit in a hardware floating-point status register (x86, for instance, uses bit 3 of the x87 FPU status register, and bit 3 of the MXCSR register), but that specific realization is not required by the standard. – Stephen Canon Jul 11 '13 at 14:04