From cb79cfde295b095dffdfb9973e1b342287b797d4 Mon Sep 17 00:00:00 2001 From: mahtab Date: Thu, 23 Jan 2020 11:45:26 +0600 Subject: [PATCH] Updated README.md implementation --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/README.md b/README.md index eb36af0..459c773 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,54 @@ # MathJs Wrapper A wrapper of the mathjs.org (https://mathjs.org/) JavaScript library for Android to evaluate math expressions. + +## Implementation + +#### Initialization + +Initialize MathJsWapper object with context. +``` +var mathJsWrapper = MathJsWrapper(this) +``` + +#### Evaluate Expressions + +1. Various supported expressions + +``` +val expression = "12 / (2.3 + 0.7)" // 2.718 +val expression = "12.7 cm to inch" // 5 inch +val expression = "sin(45 deg) ^ 2" // 0.5 +val expression = "9 / 3 + 2i" // 3 + 2i +val expression = "det([-1, 2; 3, 1])" // -7 +val expression = "111111111111111111111111111111111111111111111111+2222222222222222222222222222222222222222222222222" // 2.3333333e+48 + + +val output: String = mathJsWrapper.eval(expression) +``` + +2. Various supported expressions with variables + +``` +val expression = "a / (b + c)" // 2.718 +val map = HashMap() +map["a"] = 12 +map["b"] = 2.3 +map["c"] = 0.7 + +val output: String = mathJsWrapper.eval(expression, map) +``` + +#### Traverse specified node of Expressions + +You can get all the nodes from expressions such as 'SymbolNode', 'OperatorNode', 'ConstantNode', 'ParenthesisNode' +``` +val expression = "a / (b + c)" // 2.718 +val list = mathJsWrapper.getExpressionNodes(expression, NodeType.SymbolNode) // ["a","b","c"] +``` + +#### Remove MathJsWapper in `onDestroy()` + +Deallocate instances after being used. +``` +mathJsWrapper.onDestroy() +```