Module: Math

Defined in:
lib/rails_units/math.rb

Class Method Summary collapse

Class Method Details

.atan2(x, y) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/rails_units/math.rb', line 88

def atan2(x,y)
  case
  when (x.is_a?(Unit) && y.is_a?(Unit)) && (x !~ y)
    raise ArgumentError, "Incompatible Units"
  when (x.is_a?(Unit) && y.is_a?(Unit)) && (x =~ y)
    Math::unit_atan2(x.base_scalar, y.base_scalar)
  else
    Math::unit_atan2(x,y)
  end
end

.cbrt(n) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rails_units/math.rb', line 21

def cbrt(n)
  if Unit === n
    (n**(Rational(1,3))).to_unit 
  else
    unit_cbrt(n)
  end
end

.cos(n) ⇒ Object



41
42
43
# File 'lib/rails_units/math.rb', line 41

def cos(n)
  Unit === n ? unit_cos(n.to('radian').scalar) : unit_cos(n)
end

.cosh(n) ⇒ Object



55
56
57
# File 'lib/rails_units/math.rb', line 55

def cosh(n)
  Unit === n ? unit_cosh(n.to('radian').scalar) : unit_cosh(n)
end

.hypot(x, y) ⇒ Object

Convert parameters to consistent units and perform the function



77
78
79
80
81
82
83
# File 'lib/rails_units/math.rb', line 77

def hypot(x,y)
  if Unit === x && Unit === y
    (x**2 + y**2)**(1/2)
  else
    unit_hypot(x,y)
  end
end

.sin(n) ⇒ Object



34
35
36
# File 'lib/rails_units/math.rb', line 34

def sin(n)
 Unit === n ? unit_sin(n.to('radian').scalar) : unit_sin(n)
end

.sinh(n) ⇒ Object



48
49
50
# File 'lib/rails_units/math.rb', line 48

def sinh(n)
  Unit === n ? unit_sinh(n.to('radian').scalar) : unit_sinh(n)
end

.sqrt(n) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rails_units/math.rb', line 8

def sqrt(n)
  if Unit === n
    (n**(Rational(1,2))).to_unit 
  else
    unit_sqrt(n)
  end
end

.tan(n) ⇒ Object



62
63
64
# File 'lib/rails_units/math.rb', line 62

def tan(n)
 Unit === n ? unit_tan(n.to('radian').scalar) : unit_tan(n)
end

.tanh(n) ⇒ Object



69
70
71
# File 'lib/rails_units/math.rb', line 69

def tanh(n)
  Unit === n ? unit_tanh(n.to('radian').scalar) : unit_tanh(n)
end

.unit_atan2Object



87
# File 'lib/rails_units/math.rb', line 87

alias :unit_atan2 :atan2

.unit_cbrtObject



20
# File 'lib/rails_units/math.rb', line 20

alias :unit_cbrt :cbrt

.unit_cosObject



40
# File 'lib/rails_units/math.rb', line 40

alias :unit_cos :cos

.unit_coshObject



54
# File 'lib/rails_units/math.rb', line 54

alias :unit_cosh :cosh

.unit_hypotObject



75
# File 'lib/rails_units/math.rb', line 75

alias :unit_hypot :hypot

.unit_sinObject

:nocov:



33
# File 'lib/rails_units/math.rb', line 33

alias :unit_sin :sin

.unit_sinhObject



47
# File 'lib/rails_units/math.rb', line 47

alias :unit_sinh :sinh

.unit_sqrtObject



7
# File 'lib/rails_units/math.rb', line 7

alias :unit_sqrt :sqrt

.unit_tanObject



61
# File 'lib/rails_units/math.rb', line 61

alias :unit_tan :tan

.unit_tanhObject



68
# File 'lib/rails_units/math.rb', line 68

alias :unit_tanh :tanh