The behaviour of floating point division by zero

后端 未结 7 1771
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 02:39

Consider

#include 
int main()
{
    double a = 1.0 / 0;
    double b = -1.0 / 0;
    double c = 0.0 / 0;
    std::cout << a << b          


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 02:48

    As to the submitter's question 'Who's correct?', it is perfectly OK to say that both answers are correct. The fact that the C standard describes the behavior as 'undefined' DOES NOT dictate what the underlying hardware actually does; it merely means that if you want your program to be meaningful according to the standard you -may not assume- that the hardware actually implements that operation. But if you happen to be running on hardware that implements the IEEE standard, you will find the operation is in fact implemented, with the results as stipulated by the IEEE standard.

提交回复
热议问题