Module: Dieses::Support::Float

Included in:
Dieses::Support
Defined in:
lib/dieses/support/float.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.precisionObject

Returns the value of attribute precision.



9
10
11
# File 'lib/dieses/support/float.rb', line 9

def precision
  @precision
end

Instance Method Details

#almost_equal(left, right, precision: Float.precision) ⇒ Object



20
21
22
# File 'lib/dieses/support/float.rb', line 20

def almost_equal(left, right, precision: Float.precision)
  round(left, precision) == round(right, precision)
end

#almost_greater_or_equal(left, right, precision: Float.precision) ⇒ Object



28
29
30
# File 'lib/dieses/support/float.rb', line 28

def almost_greater_or_equal(left, right, precision: Float.precision)
  round(left, precision) >= round(right, precision)
end

#almost_greater_than(left, right, precision: Float.precision) ⇒ Object



36
37
38
# File 'lib/dieses/support/float.rb', line 36

def almost_greater_than(left, right, precision: Float.precision)
  round(left, precision) > round(right, precision)
end

#almost_less_or_equal(left, right, precision: Float.precision) ⇒ Object



24
25
26
# File 'lib/dieses/support/float.rb', line 24

def almost_less_or_equal(left, right, precision: Float.precision)
  round(left, precision) <= round(right, precision)
end

#almost_less_than(left, right, precision: Float.precision) ⇒ Object



32
33
34
# File 'lib/dieses/support/float.rb', line 32

def almost_less_than(left, right, precision: Float.precision)
  round(left, precision) < round(right, precision)
end

#approx(float, precision = nil) ⇒ Object



16
17
18
# File 'lib/dieses/support/float.rb', line 16

def approx(float, precision = nil)
  float.round(precision || Float.precision)
end

#round(float, precision) ⇒ Object



12
13
14
# File 'lib/dieses/support/float.rb', line 12

def round(float, precision)
  precision ? float.round(precision) : float
end