exprtk

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 2 Imported by: 5

README

Go Mathematical Expression Toolkit

Go Doc Reference Build Status Go Report Card

The Go Expression Toolkit (Go-ExprTk) is a wrapper library based on C++ Mathematical Expression Toolkit Library (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.

Installation

go get github.com/Pramod-Devireddy/go-exprtk

Examples

package main

import (
	"fmt"

	"github.com/Pramod-Devireddy/go-exprtk"
)

func main() {
	exprtkObj := exprtk.NewExprtk()
	defer exprtkObj.Delete()

	exprtkObj.SetExpression("(x + 2)*(y-2)")

	exprtkObj.AddDoubleVariable("x")
	exprtkObj.AddDoubleVariable("y")

	err := exprtkObj.CompileExpression()
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	exprtkObj.SetDoubleVariableValue("x", 18)
	exprtkObj.SetDoubleVariableValue("y", 32)

	fmt.Println(exprtkObj.GetEvaluatedValue())
}

Check out more Examples

⚡ Features

The Go-ExprTk library has the following capabilities:

  • Mathematical operators (+, -, *, /, %, ^)

  • Functions (min, max, avg, sum, abs, ceil, floor, round, roundn, exp, log, log10, logn, pow, root, sqrt, clamp, inrange, swap)

  • Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh, d2r, r2d, d2g, g2d, hyp)

  • Equalities & Inequalities (=, ==, <>, !=, <, <=, >, >=)

  • Assignment (:=, +=, -=, *=, /=, %=)

  • Logical operators (and, nand, nor, not, or, xor, xnor, mand, mor)

  • Control structures (if-then-else, ternary conditional, switch case, return-statement)

  • Loop structures (while loop, for loop, repeat until loop, break, continue)

  • Optimization of expressions (constant folding, strength reduction, operator coupling, special functions and dead code elimination)

  • String operations (equalities, inequalities, logical operators, concatenation and sub-ranges)

  • Expression local variables, vectors and strings

  • User defined variables, vectors, strings, constants and function support

  • Multivariate function composition

  • Multiple sequence point and sub expression support

  • Numeric integration and differentiation

  • 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

❤️ Credits

This module could not be possible without the ExprTk library by Arash Partow and the idea of creating the wrapper module by Narayana Rao G S

Published under MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoExprtk

type GoExprtk struct {
	// contains filtered or unexported fields
}

GoExprtk ...Exprtk Structure

func NewExprtk

func NewExprtk() GoExprtk

NewExprtk ... Creates a new object

func (GoExprtk) AddDoubleVariable

func (obj GoExprtk) AddDoubleVariable(x string)

AddDoubleVariable ... Adds variable to the expression

func (GoExprtk) AddStringVariable

func (obj GoExprtk) AddStringVariable(x string)

AddStringVariable ... Adds variable to the expression

func (GoExprtk) AddVectorVariable

func (obj GoExprtk) AddVectorVariable(x string)

AddVectorVariable ... Adds variable to the expression

func (GoExprtk) CompileExpression

func (obj GoExprtk) CompileExpression() error

CompileExpression ... Compiles the Expression

func (GoExprtk) Delete added in v1.0.1

func (obj GoExprtk) Delete()

Delete ... Destroys the created object and releases the memory

func (GoExprtk) GetEvaluatedValue

func (obj GoExprtk) GetEvaluatedValue() float64

GetEvaluatedValue ... Returns the evaluated value

func (GoExprtk) SetDoubleVariableValue

func (obj GoExprtk) SetDoubleVariableValue(varName string, val float64)

SetDoubleVariableValue ... Sets value to the variable

func (GoExprtk) SetExpression

func (obj GoExprtk) SetExpression(expr string)

SetExpression ... Sets an Expression

func (GoExprtk) SetStringVariableValue

func (obj GoExprtk) SetStringVariableValue(varName string, val string)

SetStringVariableValue ... Sets value to the variable

func (GoExprtk) SetVectorVariableValue

func (obj GoExprtk) SetVectorVariableValue(varName string, val []float64)

SetVectorVariableValue ... Sets value to the variable

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL