module FloatApprox
Constants
- VERSION
Public Instance Methods
absolute_approx(other, epsilon=Float::EPSILON)
click to toggle source
# File lib/float_approx.rb, line 12 def absolute_approx(other, epsilon=Float::EPSILON) return (other - self).abs <= epsilon end
approx(other, relative_epsilon=Float::EPSILON, epsilon=Float::EPSILON)
click to toggle source
# File lib/float_approx.rb, line 5 def approx(other, relative_epsilon=Float::EPSILON, epsilon=Float::EPSILON) difference = other - self return true if difference.abs <= epsilon relative_error = (difference / (self > other ? self : other)).abs return relative_error <= relative_epsilon end