P
pavan
See the following code :
#include <iostream>
using namespace std;
float f1 = 1.0e+6;
// This function just returns f1.
float value1()
{
return f1;
}
void main()
{
float f3 = f1 * f1 - f1 * f1;
cout<<"f3 = "<<f3<<endl;
float f4 = (f1 * value1()) - (f1 * value1());
cout<<"f4 = "<<f4<<endl;
}
The result is :
f3 = 0
f4 = -4096
I expected that the second result should also be zero, as
both are same.
But I am getting -4096.
Can you tell me the reason for this behavior.
The above behavior is not shown by double and long double.
Thanks,
pavan.
#include <iostream>
using namespace std;
float f1 = 1.0e+6;
// This function just returns f1.
float value1()
{
return f1;
}
void main()
{
float f3 = f1 * f1 - f1 * f1;
cout<<"f3 = "<<f3<<endl;
float f4 = (f1 * value1()) - (f1 * value1());
cout<<"f4 = "<<f4<<endl;
}
The result is :
f3 = 0
f4 = -4096
I expected that the second result should also be zero, as
both are same.
But I am getting -4096.
Can you tell me the reason for this behavior.
The above behavior is not shown by double and long double.
Thanks,
pavan.