Module: Dieses::Support::Float
- Included in:
- Dieses::Support
- Defined in:
- lib/dieses/support/float.rb
Class Attribute Summary collapse
-
.precision ⇒ Object
Returns the value of attribute precision.
Instance Method Summary collapse
- #almost_equal(left, right, precision: Float.precision) ⇒ Object
- #almost_greater_or_equal(left, right, precision: Float.precision) ⇒ Object
- #almost_greater_than(left, right, precision: Float.precision) ⇒ Object
- #almost_less_or_equal(left, right, precision: Float.precision) ⇒ Object
- #almost_less_than(left, right, precision: Float.precision) ⇒ Object
- #approx(float, precision = nil) ⇒ Object
- #round(float, precision) ⇒ Object
Class Attribute Details
.precision ⇒ Object
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 |