+ 4

How is float stored in c++? How can two float numbers be compared?

8th Jul 2018, 6:26 AM
Saundarya Kumar
Saundarya Kumar - avatar
5 Respostas
8th Jul 2018, 7:05 AM
Omkar Gurav
Omkar Gurav - avatar
+ 2
floats in c++ are stored as they are in computers generally, it has bits dedicated to the sign, exponent and mantissa. read more here: https://en.m.wikipedia.org/wiki/IEEE_754
8th Jul 2018, 8:02 AM
hinanawi
hinanawi - avatar
+ 2
The problem is that doing maths with floats is inexact, so you need to do "inexact comparison" too. It really depends on your application though. https://code.sololearn.com/cfpN6pnAjVNk/?ref=app
8th Jul 2018, 9:01 AM
Schindlabua
Schindlabua - avatar
+ 1
To store the float c++ followed IEEE-745 standard. Please Google it read more about IEEE standard. you can compare two float using if condition. float ft=5.35; if (5.35f == ft) cout<<"Match found"<<endl;
8th Jul 2018, 6:49 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar