Class: Maths::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/maths/functions.rb

Constant Summary collapse

FUNCTIONS =
{
  "sqrt" => Proc.new { |val| BigDecimal.new(Math.sqrt(val).to_s) },
  "cbrt" => Proc.new { |val| BigDecimal.new(Math.cbrt(val).to_s) },
  "sin" => Proc.new { |val| BigDecimal.new(Math.sin(val).to_s) },
  "asin" => Proc.new { |val| BigDecimal.new(Math.sin(val).to_s) },
  "sinh" => Proc.new { |val| BigDecimal.new(Math.sinh(val).to_s) },
  "asinh" => Proc.new { |val| BigDecimal.new(Math.asinh(val).to_s) },
  "cos" => Proc.new { |val| BigDecimal.new(Math.cos(val).to_s) },
  "acos" => Proc.new { |val| BigDecimal.new(Math.acos(val).to_s) },
  "cosh" => Proc.new { |val| BigDecimal.new(Math.cosh(val).to_s) },
  "acosh" => Proc.new { |val| BigDecimal.new(Math.acosh(val).to_s) },
  "tan" => Proc.new { |val| BigDecimal.new(Math.tan(val).to_s) },
  "atan" => Proc.new { |val| BigDecimal.new(Math.atan(val).to_s) },
  "tanh" => Proc.new { |val| BigDecimal.new(Math.tanh(val).to_s) },
  "atanh" => Proc.new { |val| BigDecimal.new(Math.atanh(val).to_s) },
  "ln" => Proc.new { |val| BigDecimal.new(Math.log(val).to_s) },
  "log" => Proc.new { |val| BigDecimal.new(Math.log10(val).to_s) },
  "log2" => Proc.new { |val| BigDecimal.new(Math.log2(val).to_s) },
  "floor" => Proc.new { |val| BigDecimal.new(val.floor.to_s) },
  "ceil" => Proc.new { |val| BigDecimal.new(val.ceil.to_s) },
  "ceiling" => Proc.new { |val| BigDecimal.new(val.ceil.to_s) },
  "round" => Proc.new { |val| BigDecimal.new(val.round.to_s) }
}

Class Method Summary collapse

Class Method Details

.exec(function, value) ⇒ Object



27
28
29
# File 'lib/maths/functions.rb', line 27

def self.exec(function, value)
  FUNCTIONS[function].call(value)
end