Class: Likes::Support::FloatWithError

Inherits:
Object
  • Object
show all
Defined in:
lib/likes/support.rb

Overview

Job: Understands float comparision in computer world

Constant Summary collapse

ALLOWED_ERROR =
1e-9

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ FloatWithError

Returns a new instance of FloatWithError.



21
22
23
# File 'lib/likes/support.rb', line 21

def initialize(value)
  @value = value
end

Class Method Details

.lift(value) ⇒ Object



16
17
18
19
# File 'lib/likes/support.rb', line 16

def self.lift(value)
  return value if FloatWithError === value
  FloatWithError.new(value)
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/likes/support.rb', line 25

def ==(other)
  (self.value - FloatWithError.lift(other).value).abs < ALLOWED_ERROR
end