|
1 | 1 | <p align="center"> |
2 | | - <h1 align="center"> Go Mathematical Expression Toolkit </h1> |
| 2 | + <h1 align="center"> Go Mathematical Expression Toolkit</h1> |
3 | 3 | </p> |
| 4 | + |
| 5 | +The Go Expression Toolkit (Go-ExprTk) is a wrapper library based on C++ Mathematical Expression Toolkit Library ([ExprTk](http://www.partow.net/programming/exprtk/)). It is a simple to use, easy to integrate and extremely efficient run-time mathematical expression parser and evaluation engine. Go-ExprTk supports numerous forms of functional, logical and vector processing semantics and is very easily extendible. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +go get github.com/Pramod-Devireddy/go-exprtk |
| 11 | +``` |
| 12 | + |
| 13 | +## Examples |
| 14 | + |
| 15 | +```Go |
| 16 | +package main |
| 17 | + |
| 18 | +import ( |
| 19 | + "fmt" |
| 20 | + |
| 21 | + "github.com/Pramod-Devireddy/go-exprtk" |
| 22 | +) |
| 23 | + |
| 24 | +func main() { |
| 25 | + exprtkObj := exprtk.NewExprtk() |
| 26 | + |
| 27 | + exprtkObj.SetExpression("(x + 2)*(y-2)") |
| 28 | + |
| 29 | + exprtkObj.AddDoubleVariable("x") |
| 30 | + exprtkObj.AddDoubleVariable("y") |
| 31 | + |
| 32 | + err := exprtkObj.CompileExpression() |
| 33 | + if err != nil { |
| 34 | + fmt.Println(err.Error()) |
| 35 | + return |
| 36 | + } |
| 37 | + |
| 38 | + exprtkObj.SetDoubleVariableValue("x", 18) |
| 39 | + exprtkObj.SetDoubleVariableValue("y", 32) |
| 40 | + |
| 41 | + fmt.Println(exprtkObj.GetEvaluatedValue()) |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Check out more [Examples](https://github.com/Pramod-Devireddy/go-exprtk/tree/main/examples) |
| 46 | + |
| 47 | + |
| 48 | +## ⚡ Features |
| 49 | + |
| 50 | +The Go-ExprTk library has the following capabilities: |
| 51 | + |
| 52 | +* Mathematical operators (+, -, *, /, %, ^) |
| 53 | + |
| 54 | +* Functions (min, max, avg, sum, abs, ceil, floor, round, roundn, exp, log, log10, logn, pow, root, sqrt, clamp, inrange, swap) |
| 55 | + |
| 56 | +* Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh, d2r, r2d, d2g, g2d, hyp) |
| 57 | + |
| 58 | +* Equalities & Inequalities (=, ==, <>, !=, <, <=, >, >=) |
| 59 | + |
| 60 | +* Assignment (:=, +=, -=, *=, /=, %=) |
| 61 | + |
| 62 | +* Logical operators (and, nand, nor, not, or, xor, xnor, mand, mor) |
| 63 | + |
| 64 | +* Control structures (if-then-else, ternary conditional, switch case, return-statement) |
| 65 | + |
| 66 | +* Loop structures (while loop, for loop, repeat until loop, break, continue) |
| 67 | + |
| 68 | +* Optimization of expressions (constant folding, strength reduction, operator coupling, special functions and dead code elimination) |
| 69 | + |
| 70 | +* String operations (equalities, inequalities, logical operators, concatenation and sub-ranges) |
| 71 | + |
| 72 | +* Expression local variables, vectors and strings |
| 73 | + |
| 74 | +* User defined variables, vectors, strings, constants and function support |
| 75 | + |
| 76 | +* Multivariate function composition |
| 77 | + |
| 78 | +* Multiple sequence point and sub expression support |
| 79 | + |
| 80 | +* Numeric integration and differentiation |
| 81 | + |
| 82 | +* Vector Processing: BLAS-L1 (axpy, axpby, axpb), all/any-true/false, count, rotate-left/right, shift-left/right, sort, nth_element, iota, sum, kahan-sum, dot-product, copy |
| 83 | + |
| 84 | + |
| 85 | +## ❤️ Credits |
| 86 | + |
| 87 | +This module could not be possible without the [ExprTk](http://www.partow.net/programming/exprtk/) library by [Arash Partow](https://github.com/ArashPartow) and the idea of creating the wrapper module by [Narayana Rao G S](https://twitter.com/narayanraogs) |
0 commit comments