Class: Numeric

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

Instance Method Summary collapse

Instance Method Details

#in_delta?(orig, delta = 0.001) ⇒ Boolean Also known as: close?

Is self and given number within delta tolerance.

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

Returns:

  • (Boolean)

107
108
109
110
# File 'lib/ae/core_ext/helpers.rb', line 107

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

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

Verify epsilon tolerance.

Returns:

  • (Boolean)

116
117
118
# File 'lib/ae/core_ext/helpers.rb', line 116

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