Sha256: cb638e329681f90305db5f3f7a8b80167678337bbe3b30518386d414a4d44b7c
Contents?: true
Size: 928 Bytes
Versions: 1
Compression:
Stored size: 928 Bytes
Contents
# Approminately equals returns true when values are close enough, within some # distance epsilon above or below the given value. # Adds the approximately equals operation to Numeric and its progeny. class Numeric # The initial default distance from a Numeric below which it is considered # to be approximately equal to a another Numeric. @@epsilon = 0.0000000001 # The default distance from a Numeric below which it is considered to be # approximately equal to a another Numeric. def Numeric.epsilon @@epsilon end # Sets the default distance for approximately equals comparisons. def Numeric.epsilon=(epsilon) @@epsilon = epsilon.abs end # returns true if the difference between the instance and the given Numeric # is less than the given distance. def approximately_equals?(value,epsilon=@@epsilon) (self - value).abs < epsilon end alias =~ approximately_equals? end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
eymiha_math-0.1.0 | lib/approximately_equals.rb |