emath is a math parser/evaluator library. it first converts raw expression [which is given as string] into AST and then evaluates it.
emath allows you to manipulate the generated AST, so it would not limit your POWER as a Nim programmer 👑.
Here's the flow:
string ──parsing──► AST ──evaluating──► number
Example:
import src/emath # evaluating with default functions and variables echo "1 + sin(PI)".parse.eval # 1.0 # using custom variables and functions import std/tables import emath/defaults let vars = toTable { "myvar": 6.6 } var fns = defaultFns fns["pow2"] = proc(args: seq[float]): float = args[0] * args[0] let ans = "myvar * pow2(3)".parse.eval(vars, fns) echo ans # 59.4
Procs
func eval(mn: EMathNode): float {....raises: [EMathNotDefined, Exception, EMathEvalError], tags: [RootEffect].}
- calculates the final answer with default variables and default functions
func eval(mn: EMathNode; varLookup: EMathVarLookup; fnLookup: EMathFnLookup): float {. ...raises: [EMathNotDefined, EMathNotDefined, Exception, EMathEvalError], tags: [RootEffect].}
- calculates the final answer
func isValid(mn: EMathNode): bool {....raises: [], tags: [].}
- check for any AST errors in genereated AST
Exports
-
EMathParseError, emskVar, EMathTokenError, EMathNotDefined, emskFunc, EMathSymbolKind, EMathEvalError, EMathException, left, emoPow, emoDiv, emoAssign, emoMod, emoAlmostEq, EMathTokenKind, emoLessEq, emoEq, EMathNode, emoPlus, emoMinus, emoNotFact, emoMult, EMathOperator, EMathToken, right, emoNotEq, EMathFnLookup, emoLess, emoLarger, emoLargerEq, EMathFn, EMathVarLookup, emoAnd, emoOr, EMathNodeKind, priority, inside