Module: Sevgi::Function::Math
- Included in:
- Sevgi::Function
- Defined in:
- lib/sevgi/function/math.rb
Class Attribute Summary collapse
-
.precision ⇒ Object
Returns the value of attribute precision.
Instance Method Summary collapse
- #acos(value) ⇒ Object
- #acot(value) ⇒ Object
- #approx(float, precision = nil) ⇒ Object
- #asin(value) ⇒ Object
- #atan(value) ⇒ Object
- #atan2(y, x) ⇒ Object
- #cos(degrees) ⇒ Object
- #cot(degrees) ⇒ Object
- #count(length, division) ⇒ Object
- #eq?(left, right, precision: nil) ⇒ Boolean
- #ge?(left, right, precision: nil) ⇒ Boolean
- #gt?(left, right, precision: nil) ⇒ Boolean
- #le?(left, right, precision: nil) ⇒ Boolean
- #lt?(left, right, precision: nil) ⇒ Boolean
- #round(float, precision) ⇒ Object
- #sin(degrees) ⇒ Object
- #tan(degrees) ⇒ Object
- #to_degrees(radians) ⇒ Object
- #to_radians(degrees) ⇒ Object
- #zero?(value, precision: nil) ⇒ Boolean
Class Attribute Details
.precision ⇒ Object
Returns the value of attribute precision.
9 10 11 |
# File 'lib/sevgi/function/math.rb', line 9 def precision @precision end |
Instance Method Details
#acos(value) ⇒ Object
12 |
# File 'lib/sevgi/function/math.rb', line 12 def acos(value) = to_degrees(::Math.acos(value)) |
#acot(value) ⇒ Object
14 |
# File 'lib/sevgi/function/math.rb', line 14 def acot(value) = 90.0 - to_degrees(::Math.atan(value)) |
#approx(float, precision = nil) ⇒ Object
16 |
# File 'lib/sevgi/function/math.rb', line 16 def approx(float, precision = nil) = float.round(precision || Function::Math.precision) |
#asin(value) ⇒ Object
18 |
# File 'lib/sevgi/function/math.rb', line 18 def asin(value) = to_degrees(::Math.asin(value)) |
#atan(value) ⇒ Object
20 |
# File 'lib/sevgi/function/math.rb', line 20 def atan(value) = to_degrees(::Math.atan(value)) |
#atan2(y, x) ⇒ Object
22 |
# File 'lib/sevgi/function/math.rb', line 22 def atan2(y, x) = to_degrees(::Math.atan2(y, x)) |
#cos(degrees) ⇒ Object
24 |
# File 'lib/sevgi/function/math.rb', line 24 def cos(degrees) = ::Math.cos(to_radians(degrees)) |
#cot(degrees) ⇒ Object
26 |
# File 'lib/sevgi/function/math.rb', line 26 def cot(degrees) = 1.0 / ::Math.tan(to_radians(degrees)) |
#count(length, division) ⇒ Object
28 |
# File 'lib/sevgi/function/math.rb', line 28 def count(length, division) = (length / division.to_f).to_i |
#eq?(left, right, precision: nil) ⇒ Boolean
30 |
# File 'lib/sevgi/function/math.rb', line 30 def eq?(left, right, precision: nil) = approx(left, precision) == approx(right, precision) |
#ge?(left, right, precision: nil) ⇒ Boolean
32 |
# File 'lib/sevgi/function/math.rb', line 32 def ge?(left, right, precision: nil) = approx(left, precision) >= approx(right, precision) |
#gt?(left, right, precision: nil) ⇒ Boolean
34 |
# File 'lib/sevgi/function/math.rb', line 34 def gt?(left, right, precision: nil) = approx(left, precision) > approx(right, precision) |
#le?(left, right, precision: nil) ⇒ Boolean
36 |
# File 'lib/sevgi/function/math.rb', line 36 def le?(left, right, precision: nil) = approx(left, precision) <= approx(right, precision) |
#lt?(left, right, precision: nil) ⇒ Boolean
38 |
# File 'lib/sevgi/function/math.rb', line 38 def lt?(left, right, precision: nil) = approx(left, precision) < approx(right, precision) |
#round(float, precision) ⇒ Object
40 |
# File 'lib/sevgi/function/math.rb', line 40 def round(float, precision) = precision ? float.round(precision) : float |
#sin(degrees) ⇒ Object
42 |
# File 'lib/sevgi/function/math.rb', line 42 def sin(degrees) = ::Math.sin(to_radians(degrees)) |
#tan(degrees) ⇒ Object
44 |
# File 'lib/sevgi/function/math.rb', line 44 def tan(degrees) = ::Math.tan(to_radians(degrees)) |
#to_degrees(radians) ⇒ Object
46 |
# File 'lib/sevgi/function/math.rb', line 46 def to_degrees(radians) = radians.to_f * 180 / ::Math::PI |
#to_radians(degrees) ⇒ Object
48 |
# File 'lib/sevgi/function/math.rb', line 48 def to_radians(degrees) = degrees.to_f / 180 * ::Math::PI |
#zero?(value, precision: nil) ⇒ Boolean
50 |
# File 'lib/sevgi/function/math.rb', line 50 def zero?(value, precision: nil) = eq?(value, 0.0, precision:) |