Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/richardwilkes/toolbox/eval" "github.com/richardwilkes/toolbox/xmath/fixed" ) func main() { e := eval.NewFixedEvaluator[fixed.D4](nil, true) result, err := e.Evaluate("1 + sqrt(2)") if err != nil { panic(err) } fmt.Println(result) }
Output: 2.4142
Index ¶
- func FixedFrom[T fixed.Dx](arg any) (f64.Int[T], error)
- func FixedFunctions[T fixed.Dx]() map[string]Function
- func FloatFunctions[T constraints.Float]() map[string]Function
- func NextArg(args string) (arg, remaining string)
- type Evaluator
- type Function
- type OpFunc
- type Operator
- func Add(f OpFunc, unary UnaryOpFunc) *Operator
- func CloseParen() *Operator
- func Divide(f OpFunc) *Operator
- func Equal(f OpFunc) *Operator
- func FixedOperators[T fixed.Dx](divideByZeroReturnsZero bool) []*Operator
- func FloatOperators[T constraints.Float](divideByZeroReturnsZero bool) []*Operator
- func GreaterThan(f OpFunc) *Operator
- func GreaterThanOrEqual(f OpFunc) *Operator
- func LessThan(f OpFunc) *Operator
- func LessThanOrEqual(f OpFunc) *Operator
- func LogicalAnd(f OpFunc) *Operator
- func LogicalOr(f OpFunc) *Operator
- func Modulo(f OpFunc) *Operator
- func Multiply(f OpFunc) *Operator
- func Not(f UnaryOpFunc) *Operator
- func NotEqual(f OpFunc) *Operator
- func OpenParen() *Operator
- func Power(f OpFunc) *Operator
- func Subtract(f OpFunc, unary UnaryOpFunc) *Operator
- type UnaryOpFunc
- type VariableResolver
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixedFrom ¶ added in v1.68.1
FixedFrom attempts to convert the arg into one of the fixed.F64 types.
func FixedFunctions ¶ added in v1.68.0
FixedFunctions returns standard functions that work with 64-bit fixed-point values.
func FloatFunctions ¶ added in v1.68.0
func FloatFunctions[T constraints.Float]() map[string]Function
FloatFunctions returns standard functions that work with constraints.Float.
Types ¶
type Evaluator ¶
type Evaluator struct { Resolver VariableResolver Operators []*Operator Functions map[string]Function // contains filtered or unexported fields }
Evaluator is used to evaluate an expression. If you do not have any variables that will be resolved, you can leave Resolver unset. StdOperators() and StdFunctions() can be used to populate the Operators and Functions fields.
func NewFixedEvaluator ¶ added in v1.68.0
func NewFixedEvaluator[T fixed.Dx](resolver VariableResolver, divideByZeroReturnsZero bool) *Evaluator
NewFixedEvaluator creates a new evaluator whose number type is one of the fixed types.
func NewFloatEvaluator ¶ added in v1.68.0
func NewFloatEvaluator[T constraints.Float](resolver VariableResolver, divideByZeroReturnsZero bool) *Evaluator
NewFloatEvaluator creates a new evaluator whose number type is one of the constraints.Float types.
type Operator ¶
type Operator struct { Evaluate OpFunc EvaluateUnary UnaryOpFunc Symbol string Precedence int }
Operator provides an operator implementation for the Evaluator.
func FixedOperators ¶ added in v1.68.0
FixedOperators returns standard operators that work with 64-bit fixed-point values.
func FloatOperators ¶ added in v1.68.0
func FloatOperators[T constraints.Float](divideByZeroReturnsZero bool) []*Operator
FloatOperators returns standard operators that work with floating point values.
type UnaryOpFunc ¶
UnaryOpFunc provides a signature for an Operator's EvaluateUnary function.
type VariableResolver ¶
VariableResolver is used to resolve variables in expressions into their values.