Module: Math

Defined in:
lib/ruby_units/math.rb

Class Method Summary collapse

Class Method Details

.atan2(x, y) ⇒ Object



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

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

.cbrt(n) ⇒ Object



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

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

.cos(n) ⇒ Object



39
40
41
# File 'lib/ruby_units/math.rb', line 39

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

.cosh(n) ⇒ Object



53
54
55
# File 'lib/ruby_units/math.rb', line 53

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



75
76
77
78
79
80
81
# File 'lib/ruby_units/math.rb', line 75

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



32
33
34
# File 'lib/ruby_units/math.rb', line 32

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

.sinh(n) ⇒ Object



46
47
48
# File 'lib/ruby_units/math.rb', line 46

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/ruby_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



60
61
62
# File 'lib/ruby_units/math.rb', line 60

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

.tanh(n) ⇒ Object



67
68
69
# File 'lib/ruby_units/math.rb', line 67

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

.unit_atan2Object



85
# File 'lib/ruby_units/math.rb', line 85

alias :unit_atan2 :atan2

.unit_cbrtObject



19
# File 'lib/ruby_units/math.rb', line 19

alias :unit_cbrt :cbrt

.unit_cosObject



38
# File 'lib/ruby_units/math.rb', line 38

alias :unit_cos :cos

.unit_coshObject



52
# File 'lib/ruby_units/math.rb', line 52

alias :unit_cosh :cosh

.unit_hypotObject



73
# File 'lib/ruby_units/math.rb', line 73

alias :unit_hypot :hypot

.unit_sinObject



31
# File 'lib/ruby_units/math.rb', line 31

alias :unit_sin :sin

.unit_sinhObject



45
# File 'lib/ruby_units/math.rb', line 45

alias :unit_sinh :sinh

.unit_sqrtObject



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

alias :unit_sqrt :sqrt

.unit_tanObject



59
# File 'lib/ruby_units/math.rb', line 59

alias :unit_tan :tan

.unit_tanhObject



66
# File 'lib/ruby_units/math.rb', line 66

alias :unit_tanh :tanh