-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mahtab
committed
Jan 23, 2020
1 parent
d8527b4
commit cb79cfd
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Any>() | ||
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() | ||
``` |