Sha256: f8ad7e5f2268578b951138ca4b25d7e0e51d9f7f6a30ed3147d39f51f3da5107
Contents?: true
Size: 761 Bytes
Versions: 1
Compression:
Stored size: 761 Bytes
Contents
require 'nano/float/round_to' class Float # Determines if another number is approximately equal # within a given _n_th degree. Defaults to 100ths # if the degree is not specified. def approx?( x, n=0.01 ) return(self == x) if n == 0 self.round_to(n) == x.to_f.round_to(n) end end class Numeric # To properly support Float#approx?, # Numeric must also be augmented. def approx?(*args) self.to_f.approx?(*args) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCFloat < Test::Unit::TestCase def test_approx? f = 10.006 assert( f.approx?(10.01) ) assert( f.approx?(10, 0.1) ) end end =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.9.0 | lib/nano/float/approx.rb |