c++ calculations are un-understandable

72 Views Asked by At

I am little bit aware of c++ type conversions in calculation. But unable to understand following code output.

#include <iostream>
int main(){
    double a = 11.7 + 0.1 + 0.1 + 0.1;
    double b = 12.0;
    std::cout << (a == b) << std::endl; // output : 0
    std::cout << (a - b) << std::endl; // output : -1.77636e-15
    return 0;
}

Why this code giving that output? If you know, let me know. :> And please also suggest some technics to handle it.

0

There are 0 best solutions below