+ 5

C++: comparison precision

Who can explain this output? One less zero, and it's "false" #include <iostream> using namespace std; int main() { float a = 2.0000001; int b = 2; if(a == b){ cout << "true!"; } else { cout << "false"; } return 0; }

12th Feb 2019, 9:14 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 odpowiedzi
+ 2
Is this true independently from the compiler?
12th Feb 2019, 10:12 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
Also, can you tell me if this code precision can be improved? https://code.sololearn.com/chgZD5KdzV9m/?ref=app
12th Feb 2019, 10:16 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
I implemented (well... pasted and copied), setting up also cout.precision(): https://code.sololearn.com/co8uU4xnKKks/?ref=app Anyway, results are not different by my factorial version....
13th Feb 2019, 3:59 PM
Paolo De Nictolis
Paolo De Nictolis - avatar