Skip to content

Instantly share code, notes, and snippets.

@ZJUGuoShuai
Created August 8, 2023 08:57
Show Gist options
  • Select an option

  • Save ZJUGuoShuai/3dbfd1be9d5186d0ea470d8b1041cdc5 to your computer and use it in GitHub Desktop.

Select an option

Save ZJUGuoShuai/3dbfd1be9d5186d0ea470d8b1041cdc5 to your computer and use it in GitHub Desktop.
Machine Epsilon 的作用
#include <limits>
#include <iostream>
int main() {
float eps = std::numeric_limits<float>::epsilon();
float a = 1.0f;
float b = a + eps;
float c = a + eps / 2.0f;
std::cout << "a == b: " << std::boolalpha << (a == b) << "\n"; // false
std::cout << "a == c: " << std::boolalpha << (a == c) << "\n"; // true
return 0;
}
@ZJUGuoShuai

Copy link
Copy Markdown
Author

如何自己获得 Machine Epsilon?

In [1]: 7./3 - 4./3 -1
Out[1]: 2.220446049250313e-16

参考:https://stackoverflow.com/a/25155518/8102500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment