Module: Math

Defined in:
lib/ruby_units/math.rb

Overview

Math will convert unit objects to radians and then attempt to use the value for trigonometric functions.

Class Method Summary collapse

Class Method Details

.atan2(x, y) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_units/math.rb', line 55

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

.cos(n) ⇒ Object



20
21
22
# File 'lib/ruby_units/math.rb', line 20

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

.cosh(n) ⇒ Object



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

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



46
47
48
49
50
51
52
# File 'lib/ruby_units/math.rb', line 46

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



15
16
17
# File 'lib/ruby_units/math.rb', line 15

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

.sinh(n) ⇒ Object



25
26
27
# File 'lib/ruby_units/math.rb', line 25

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

.sqrt(n) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ruby_units/math.rb', line 6

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

.tan(n) ⇒ Object



35
36
37
# File 'lib/ruby_units/math.rb', line 35

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

.tanh(n) ⇒ Object



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

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

.unit_atan2Object



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

alias unit_atan2 atan2

.unit_cosObject



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

alias unit_cos cos

.unit_coshObject



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

alias unit_cosh cosh

.unit_hypotObject



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

alias unit_hypot hypot

.unit_sinObject



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

alias unit_sin sin

.unit_sinhObject



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

alias unit_sinh sinh

.unit_sqrtObject



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

alias unit_sqrt sqrt

.unit_tanObject



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

alias unit_tan tan

.unit_tanhObject



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

alias unit_tanh tanh