Sha256: ccee263c9582559a01b0b734dbda7ef11b4aac6d1fe58a252a0addd492064893

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

module Maths
  class Functions
    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) }
    }
    
    def self.exec(function, value)
      FUNCTIONS[function].call(value)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
maths-0.0.14 lib/maths/functions.rb
maths-0.0.13 lib/maths/functions.rb
maths-0.0.12 lib/maths/functions.rb
maths-0.0.11 lib/maths/functions.rb
maths-0.0.10 lib/maths/functions.rb
maths-0.0.9 lib/maths/functions.rb
maths-0.0.8 lib/maths/functions.rb
maths-0.0.7 lib/maths/functions.rb
maths-0.0.6 lib/maths/functions.rb