
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
