Skip to content
forked from valiot/abacus

Parses and evaluates mathematical expressions in Elixir. Inspired by math.js

License

Notifications You must be signed in to change notification settings

Finger-Ink/abacus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abacus Build status

A parser for mathematical expressions.

https://hex.pm/packages/abacus

Usage

Abacus.eval(expression, scope)

Parses and evaluates the given expression. Variables can be supplied as a map of binaries in the scope.

Examples

iex> Abacus.eval("1 + 1")
{:ok, 2}
iex> Abacus.eval("sin(floor(3 + 2.5)) / 3")
{:ok, -0.3196414248877128}
iex> Abacus.eval("a * b", %{"a" => 10, "b" => 10})
{:ok, 100}

Abacus.parse(expression)

Parses the expression and returns the syntax tree.

Features

An incomplete list of supported and planned features

  • basic operators (+, -, *, /, ^)
  • factorial (!)
  • bitwise operators (|, &, >>, <<, ~, |^ (xor))
  • support for functions
    • trigonometric functions(sin, cos, tan)
    • floating point manipulation(ceil, floor, round)
    • data set analysis (max, min, count, sum)
    • additional math functions(mod, sqrt, abs)
  • support for variables
  • support for parsing units
  • support for converting units

Installation

  1. Add abacus to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:abacus, "~> 0.4.2"}]
end
```
  1. Ensure abacus is started before your application:
```elixir
def application do
  [applications: [:abacus]]
end
```

About

Parses and evaluates mathematical expressions in Elixir. Inspired by math.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 89.2%
  • Erlang 10.8%