Skip to content

Instantly share code, notes, and snippets.

@mebjas
Created October 5, 2022 02:42
Show Gist options
  • Save mebjas/719e0a3ad53fd9564ea7c5b74c12ab9a to your computer and use it in GitHub Desktop.
Save mebjas/719e0a3ad53fd9564ea7c5b74c12ab9a to your computer and use it in GitHub Desktop.
Code with equality check on floating values
constexpr int kIterations = 10000000;
int counter = 0;
for (int i = 0; i < kIterations; ++i) {
float a = 0.151f + 0.151f;
float b = 0.101f + 0.201f;
bool d = (a == b);
if (d) {
counter++;
}
}
std::cout << "Counter = " << counter << "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment