fork(2) download
  1. #include <iostream>
  2.  
  3. bool floatcmp(float a, float b) {
  4. //check NaN
  5. return !(a < b) && !(b < a);
  6. }
  7.  
  8. int main() {
  9. using namespace std;
  10.  
  11. float a = 0.1;
  12. float b = 0.1;
  13.  
  14. // Just to be sure change is not inlined
  15. b += 1;
  16. cout << "B after increase = " << b << endl;
  17. b -= 1;
  18. cout << "B after decrease = " << b << endl;
  19.  
  20. cout << "A " << (floatcmp(a, b) ? "equals" : "is not equal to") << "B" << endl;
  21.  
  22. cout.precision(10);
  23. cout << "A = " << a << endl;
  24. cout << "B = " << b << endl;
  25. }
  26.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
B after increase = 1.1
B after decrease = 0.1
A is not equal toB
A = 0.1000000015
B = 0.1000000238