Skip to content

Instantly share code, notes, and snippets.

@pmneila
Created November 11, 2013 06:39
Show Gist options
  • Save pmneila/7408909 to your computer and use it in GitHub Desktop.
Save pmneila/7408909 to your computer and use it in GitHub Desktop.
Example of numerical issues with double values.
#include <iostream>
int main()
{
double val1 = -10.0 + 0.4*14 + 0.4;
double val2 = -10.0 + 0.4*15;
std::cout << "val1 = " << val1 << "; val2 = " << val2 << std::endl;
std::cout << (val1 == val2 ? "Equal" : "Not equal") << std::endl;
std::cout << (val1 == -4.0 ? "val1 is -4" : "val1 is not -4") << std::endl;
std::cout << (val2 == -4.0 ? "val2 is -4" : "val2 is not -4") << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment