ExDiceRoller v0.5.0-alpha ExDiceRoller.Compilers.Math
Handles compiling expressions using common mathematical operators.
iex> {:ok, tokens} = ExDiceRoller.Tokenizer.tokenize("1+x")
{:ok, [{:digit, 1, '1'}, {:basic_operator, 1, '+'}, {:var, 1, 'x'}]}
iex> {:ok, parse_tree} = ExDiceRoller.Parser.parse(tokens)
{:ok, {{:operator, '+'}, {:digit, '1'}, {:var, 'x'}}}
iex> fun = ExDiceRoller.Compilers.Math.compile(parse_tree)
iex> fun.([x: 2], [])
3
ExDiceRoller uses infix notation when working with mathematical operators. Below is the list of operators currently supported by ExDiceRoller:
+
: adds the values on both sides of the expression-
: subtracts the value on the right from the value on the left*
: multiplies the values on both sides of the expression/
: divides, with the left value as the dividend, the right the divisor%
: modulo, with the left the dividend, the right the divisor^
: exponentiation, with the left the base, the right the exponent
Link to this section Summary
Functions
Function used for modulo calculations
Link to this section Functions
Function used for modulo calculations.