Module: Math
- Defined in:
- lib/rails_units/math.rb
Class Method Summary collapse
- .atan2(x, y) ⇒ Object
- .cbrt(n) ⇒ Object
- .cos(n) ⇒ Object
- .cosh(n) ⇒ Object
-
.hypot(x, y) ⇒ Object
Convert parameters to consistent units and perform the function.
- .sin(n) ⇒ Object
- .sinh(n) ⇒ Object
- .sqrt(n) ⇒ Object
- .tan(n) ⇒ Object
- .tanh(n) ⇒ Object
- .unit_atan2 ⇒ Object
- .unit_cbrt ⇒ Object
- .unit_cos ⇒ Object
- .unit_cosh ⇒ Object
- .unit_hypot ⇒ Object
-
.unit_sin ⇒ Object
:nocov:.
- .unit_sinh ⇒ Object
- .unit_sqrt ⇒ Object
- .unit_tan ⇒ Object
- .unit_tanh ⇒ Object
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_atan2 ⇒ Object
87 |
# File 'lib/rails_units/math.rb', line 87 alias :unit_atan2 :atan2 |
.unit_cbrt ⇒ Object
20 |
# File 'lib/rails_units/math.rb', line 20 alias :unit_cbrt :cbrt |
.unit_cos ⇒ Object
40 |
# File 'lib/rails_units/math.rb', line 40 alias :unit_cos :cos |
.unit_cosh ⇒ Object
54 |
# File 'lib/rails_units/math.rb', line 54 alias :unit_cosh :cosh |
.unit_hypot ⇒ Object
75 |
# File 'lib/rails_units/math.rb', line 75 alias :unit_hypot :hypot |
.unit_sinh ⇒ Object
47 |
# File 'lib/rails_units/math.rb', line 47 alias :unit_sinh :sinh |
.unit_sqrt ⇒ Object
7 |
# File 'lib/rails_units/math.rb', line 7 alias :unit_sqrt :sqrt |
.unit_tan ⇒ Object
61 |
# File 'lib/rails_units/math.rb', line 61 alias :unit_tan :tan |
.unit_tanh ⇒ Object
68 |
# File 'lib/rails_units/math.rb', line 68 alias :unit_tanh :tanh |