I am wondering why the following code works:
double x,y,z,w,v;
x = 2.0e300;
y = 1.0e300;
z = 1.0e300;
w = 1.0e300;
v = (x*y)/(z*w);
cout << "v = " << v << endl << endl;
The correct answer of 2 prints out. However, both numerator and denominator exceed the range of double, which is approximately 10 to the 308 power.
Why isn't there an overflow error on the intermediate results? Either a runtime error should occur or the final result should be nonsense instead of 2.
Thanks.
double x,y,z,w,v;
x = 2.0e300;
y = 1.0e300;
z = 1.0e300;
w = 1.0e300;
v = (x*y)/(z*w);
cout << "v = " << v << endl << endl;
The correct answer of 2 prints out. However, both numerator and denominator exceed the range of double, which is approximately 10 to the 308 power.
Why isn't there an overflow error on the intermediate results? Either a runtime error should occur or the final result should be nonsense instead of 2.
Thanks.