Class: Numeric

Inherits:
Object show all
Defined in:
lib/assay/ae/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#in_delta?(orig, delta = 0.001) ⇒ Boolean

Is the number within delta of another?

0.05.in_delta?(50000.0 / 10**6, 0.00001)

Returns:

  • (Boolean)


58
59
60
# File 'lib/assay/ae/core_ext.rb', line 58

def in_delta?(orig, delta=0.001)
  delta >= (orig - self).abs
end

#in_epsilon?(orig, epsilon = 0.001) ⇒ Boolean

Is the number within epsilon of another, relative to the smaller of the two magnitudes?

Returns:

  • (Boolean)


64
65
66
# File 'lib/assay/ae/core_ext.rb', line 64

def in_epsilon?(orig, epsilon=0.001)
  in_delta?(orig, [orig.abs, self.abs].min * epsilon)
end