Skip to content

Instantly share code, notes, and snippets.

@silentmatt
Created February 14, 2010 19:12
Show Gist options
  • Save silentmatt/304194 to your computer and use it in GitHub Desktop.
Save silentmatt/304194 to your computer and use it in GitHub Desktop.
Test two numbers for approximate equality.
function approximatelyEqual(a, b, tolerance) {
return Math.abs(a - b) < tolerance;
}
approximatelyEqual(0.1 + 0.2, 0.3, 1e-12); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment