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
- .atan2(x, y) ⇒ Numeric
- .cbrt(n) ⇒ Numeric
- .cos(n) ⇒ Numeric
- .cosh(n) ⇒ Numeric
-
.hypot(x, y) ⇒ Numeric
Convert parameters to consistent units and perform the function.
- .sin(n) ⇒ Numeric
- .sinh(n) ⇒ Numeric
- .sqrt(n) ⇒ Numeric
- .tan(n) ⇒ Numeric
- .tanh(n) ⇒ Numeric
- .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) ⇒ Numeric
113 114 115 116 117 118 119 120 |
# File 'lib/ruby_units/math.rb', line 113 def atan2(x, y) raise ArgumentError, 'Incompatible RubyUnits::Units' if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && !x.compatible?(y) if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && x.compatible?(y) Math.unit_atan2(x.base_scalar, y.base_scalar) else Math.unit_atan2(x, y) end end |
.cbrt(n) ⇒ Numeric
22 23 24 25 26 27 28 |
# File 'lib/ruby_units/math.rb', line 22 def cbrt(n) if RubyUnits::Unit === n (n**Rational(1, 3)).to_unit else unit_cbrt(n) end end |
.cos(n) ⇒ Numeric
48 49 50 |
# File 'lib/ruby_units/math.rb', line 48 def cos(n) RubyUnits::Unit === n ? unit_cos(n.convert_to('radian').scalar) : unit_cos(n) end |
.cosh(n) ⇒ Numeric
68 69 70 |
# File 'lib/ruby_units/math.rb', line 68 def cosh(n) RubyUnits::Unit === n ? unit_cosh(n.convert_to('radian').scalar) : unit_cosh(n) end |
.hypot(x, y) ⇒ Numeric
Convert parameters to consistent units and perform the function
99 100 101 102 103 104 105 |
# File 'lib/ruby_units/math.rb', line 99 def hypot(x, y) if RubyUnits::Unit === x && RubyUnits::Unit === y (x**2 + y**2)**Rational(1, 2) else unit_hypot(x, y) end end |
.sin(n) ⇒ Numeric
38 39 40 |
# File 'lib/ruby_units/math.rb', line 38 def sin(n) RubyUnits::Unit === n ? unit_sin(n.convert_to('radian').scalar) : unit_sin(n) end |
.sinh(n) ⇒ Numeric
58 59 60 |
# File 'lib/ruby_units/math.rb', line 58 def sinh(n) RubyUnits::Unit === n ? unit_sinh(n.convert_to('radian').scalar) : unit_sinh(n) end |
.sqrt(n) ⇒ Numeric
6 7 8 9 10 11 12 |
# File 'lib/ruby_units/math.rb', line 6 def sqrt(n) if n.is_a?(RubyUnits::Unit) (n**Rational(1, 2)).to_unit else unit_sqrt(n) end end |
.tan(n) ⇒ Numeric
78 79 80 |
# File 'lib/ruby_units/math.rb', line 78 def tan(n) RubyUnits::Unit === n ? unit_tan(n.convert_to('radian').scalar) : unit_tan(n) end |
.tanh(n) ⇒ Numeric
88 89 90 |
# File 'lib/ruby_units/math.rb', line 88 def tanh(n) RubyUnits::Unit === n ? unit_tanh(n.convert_to('radian').scalar) : unit_tanh(n) end |
.unit_atan2 ⇒ Object
111 |
# File 'lib/ruby_units/math.rb', line 111 alias unit_atan2 atan2 |
.unit_cbrt ⇒ Object
20 |
# File 'lib/ruby_units/math.rb', line 20 alias unit_cbrt cbrt |
.unit_cos ⇒ Object
46 |
# File 'lib/ruby_units/math.rb', line 46 alias unit_cos cos |
.unit_cosh ⇒ Object
66 |
# File 'lib/ruby_units/math.rb', line 66 alias unit_cosh cosh |
.unit_hypot ⇒ Object
96 |
# File 'lib/ruby_units/math.rb', line 96 alias unit_hypot hypot |
.unit_sin ⇒ Object
:nocov:
36 |
# File 'lib/ruby_units/math.rb', line 36 alias unit_sin sin |
.unit_sinh ⇒ Object
56 |
# File 'lib/ruby_units/math.rb', line 56 alias unit_sinh sinh |
.unit_sqrt ⇒ Object
4 |
# File 'lib/ruby_units/math.rb', line 4 alias unit_sqrt sqrt |
.unit_tan ⇒ Object
76 |
# File 'lib/ruby_units/math.rb', line 76 alias unit_tan tan |
.unit_tanh ⇒ Object
86 |
# File 'lib/ruby_units/math.rb', line 86 alias unit_tanh tanh |