View Source Cogito.Maths (Cogito v1.0.0)

Maths expression parser.

Possible inputs:

  • ---(+ 10)
  • (1 + 2 + 3 - 4 + 5) - 4 * -10
  • 3.14 / 100 * 10000 - (100.0 + (100.1 + 100.2))
  • ((2 * (3 + 4) / 7) + 3) / -5

With custom operations:

  • 1 min 2
  • 10 + 20 max (100.5 min 29.9)
  • 24 max 3 hypot 4 - 2

With variables:

  • y max 3 hypot 4 - x
  • ((x1 * (x2 + x3) / 7) + 3) / -x4

Summary

Functions

binary(arg, operations)

@spec binary(Cogito.parser(), map()) :: Cogito.parser()

parser(vars)

@spec parser(map()) :: Cogito.parser()

parser!(vars)

@spec parser!(map()) :: Cogito.parser!()

term(vars)

@spec term(map()) :: Cogito.parser()

unary(vars, operations \\ %{"+" => &+/1, "-" => &-/1})

@spec unary(map(), map()) :: Cogito.parser()