Socket
Book a DemoInstallSign in
Socket

math_expression

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

math_expression

bundlerRubygems
Version
0.0.4
Version published
Maintainers
1
Created
Source

= Expression

Mathematical expression calculator. Use this gem as a calculator.

== Installation

Add this line to your application's Gemfile:

gem 'math_expression'

And then execute:

$ bundle

Or install it yourself as:

$ gem install math_expression

== Usage

require the file:

require 'Expression'

Initialize a variable:

expr = MathExpression.new

and then it is just:

expr.eval(Your_expression)

supported functions:

  • Basic arithmetics

  • exponentiation

    expr.eval('6^3')
    
  • factorial

    expr.eval('5!')
    
  • modulo operation:

    expr.eval('9 % 5')
    
  • floating numbers

  • trigonometric identities (cos, sin, tan, cosh, sinh, tanh) and their inverses (by prefixing any of them by 'arc' e.g: arccos)

  • exponential: (exp(x) return e to the power of x)

    expr.eval('exp(2)')
    
  • logarithm:

    • General: you can use log{base}(number) e.g:

      expr.eval('log2(12)')

returns the result of calling log of base 2 for the number 12.

  expr.eval('log20(123)')

etc

  • when you omit the base, the default is base 10 i.e:

    expr.eval('log(23)')
    

is the same as

  expr.eval('log10(23)')
  • for base 'e' you can use natural logarithm:

    expr.eval('ln(21)')
    
  • root functions:

    • square root:

      expr.eval('sqrt(21)')

    • for other bases use root{base}(number):

      expr.eval('root3(12)')

== Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 14 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.