Skip to content

Instantly share code, notes, and snippets.

@jstewart
Created July 23, 2010 18:14
Show Gist options
  • Save jstewart/487809 to your computer and use it in GitHub Desktop.
Save jstewart/487809 to your computer and use it in GitHub Desktop.
class Float
def approx_equal?(other,threshold)
if (self-other).abs<threshold # "<" not exact either ;-)
return true
else
return false
end
end
end
a=0.1
b=1.0-0.9
threshold=10**(-5)
p a.approx_equal?(b,threshold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment