
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
= 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
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that math_expression demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.