Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Comparing Real Numbers

Comparing whether or not two real numbers are identical is problematic due to rounding errors. See the below C++ example for an illustration:

// { autofold
#include <iostream>
#include <math.h>
using namespace std;
// }
int main() {
cout << (sqrt(3) * sqrt(3) - 3) << endl
<< (sqrt(3) * sqrt(3) == 3) << endl
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content