Class: Likes::Support::FloatWithError
- Inherits:
-
Object
- Object
- Likes::Support::FloatWithError
- 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
- #==(other) ⇒ Object
-
#initialize(value) ⇒ FloatWithError
constructor
A new instance of FloatWithError.
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 |