Created
August 8, 2023 08:57
-
-
Save ZJUGuoShuai/3dbfd1be9d5186d0ea470d8b1041cdc5 to your computer and use it in GitHub Desktop.
Machine Epsilon 的作用
This file contains hidden or 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 <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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如何自己获得 Machine Epsilon?
参考:https://stackoverflow.com/a/25155518/8102500