Sha256: c7413c7b5b558a6e51f2761e8bac29da3e72fdd7efd39f3d11e66d6ea1e8ff17
Contents?: true
Size: 604 Bytes
Versions: 21
Compression:
Stored size: 604 Bytes
Contents
class Numeric # 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 - x).abs <= n 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) ) assert( 100.4.approx?(100.6, 1) ) end end =end
Version data entries
21 entries across 21 versions & 1 rubygems