Created
January 24, 2016 11:41
-
-
Save LiamKarlMitchell/7167108c4fb1bf5de47b to your computer and use it in GitHub Desktop.
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
// A way to compare two floating point numbers for "equality". | |
const EPSILON = 0.00000001; | |
function fEqual(a, b) { | |
return ((a - b) < EPSILON && (b - a) < EPSILON); | |
} | |
// An infamous mistake by rookies is to notice the following. | |
// 0.1 + 0.2 == 0.3 | |
// And think it is a mistake when the language says false. Us humans would just say 0.3. | |
// But because of how float points work in computer you end up with something like 0.30000000000000004. | |
// For more information definatly read this: http://floating-point-gui.de/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment