Module: Sevgi::Function::Math

Included in:
Sevgi::Function
Defined in:
lib/sevgi/function/math.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.precisionObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


50
# File 'lib/sevgi/function/math.rb', line 50

def zero?(value, precision: nil) = eq?(value, 0.0, precision:)