Skip to content

Commit

Permalink
Updated README.md implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtab committed Jan 23, 2020
1 parent d8527b4 commit cb79cfd
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
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()
```

0 comments on commit cb79cfd

Please sign in to comment.