Class: Float
- Defined in
- lib/kyanite/numeric/float.rb
Numeric Additions
- Kyanite tests and examples
- Usage
-
require 'kyanite/numeric'
Instance Method Summary (collapse)
-
- (Boolean) fuzzy_equal?(other, error_max = 0.000001)
Fuzzy comparison of Floats.
Instance Method Details
- (Boolean) fuzzy_equal?(other, error_max = 0.000001)
Fuzzy comparison of Floats. Example:
(98.6).fuzzy_equal?(98.66) => false
(98.6).fuzzy_equal?(98.66, 0.001) => true
22 23 24 25 26 27 28 |
# File 'lib/kyanite/numeric/float.rb', line 22 def fuzzy_equal?(other, error_max=0.000001) diff = other - self return true if diff.abs <= Float::EPSILON relative_error = (diff / (self > other ? self : other)).abs #puts relative_error return relative_error <= error_max end |