Created
November 11, 2013 06:39
-
-
Save pmneila/7408909 to your computer and use it in GitHub Desktop.
Example of numerical issues with double values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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