This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
floating_point_comparison [2022/04/29 23:39] max created |
floating_point_comparison [2022/04/29 23:54] (current) max |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Floating-point number comparison ====== | ||
+ | |||
+ | |||
Floating-point numbers are almost always stored inaccurately in computers' | Floating-point numbers are almost always stored inaccurately in computers' | ||
- | It also means that for example, 0.2 + 0.1 is not equal to 0.3; rather it is equal to 0.30000000000000004. | + | For example, |
Since computers are exact in comparison by default, you can see how you can run into issues with this. | Since computers are exact in comparison by default, you can see how you can run into issues with this. | ||
Line 9: | Line 12: | ||
The second option is simply the computer' | The second option is simply the computer' | ||
- | ==== The absolute method ==== | + | Which method the engine uses can be changed in the source code in the '' |
+ | |||
+ | ===== The absolute method | ||
The absolute method takes the absolute value of '' | The absolute method takes the absolute value of '' | ||
Line 15: | Line 20: | ||
The absolute method will work, but it does not work on large values. | The absolute method will work, but it does not work on large values. | ||
- | ==== The relative method ==== | + | ===== The relative method |
- | The relative method takes the result of the absolute method | + | The relative method takes the absolute method, but multiplies the epsilon by '' |
The drawback to this method is that it does not work on small values. | The drawback to this method is that it does not work on small values. | ||
- | ==== The combined method ==== | + | ===== The combined method |
Considering the strengths and drawbacks of the two methods above, you can combine the two to overcome these limitations. | Considering the strengths and drawbacks of the two methods above, you can combine the two to overcome these limitations. | ||
- | The combined method takes the result of the absolute | + | The combined method takes the relative |
This method gives us good results, but it is not without its drawbacks since it uses the same epsilon for the relative and the absolute tolerance. | This method gives us good results, but it is not without its drawbacks since it uses the same epsilon for the relative and the absolute tolerance. | ||
For further reading, please check out [[http:// | For further reading, please check out [[http:// |