Documentation ¶
Index ¶
- Constants
- func WithFunctions(funcs Functions) treeOption
- func WithVariables(vars Variables) treeOption
- type Function
- type FunctionalValue
- type Functions
- type Number
- func (n Number) Add(other Value) Value
- func (n Number) Cos() Number
- func (n Number) Divide(other Value) Value
- func (n Number) Equal(other Number) bool
- func (n Number) Factorial() Number
- func (n Number) Float64() float64
- func (n Number) Floor() Number
- func (n Number) Int64() int64
- func (n Number) LShift(other Value) Value
- func (n Number) Mod(other Value) Value
- func (n Number) Multiply(other Value) Value
- func (n Number) Neg() Number
- func (n Number) Number() Number
- func (n Number) PowerOf(other Value) Value
- func (n Number) RShift(other Value) Value
- func (n Number) Sin() Number
- func (n Number) Sqrt() Number
- func (n Number) String() string
- func (n Number) Sub(other Value) Value
- func (n Number) Tan() Number
- func (n Number) Trunc(precision int32) Number
- type Numberer
- type Operator
- type String
- func (s String) Add(other Value) Value
- func (s String) Divide(other Value) Value
- func (s String) Equal(other String) bool
- func (s String) LShift(Value) Value
- func (s String) Mod(Value) Value
- func (s String) Multiply(other Value) Value
- func (s String) Number() Number
- func (s String) PowerOf(Value) Value
- func (s String) RShift(Value) Value
- func (s String) String() string
- func (s String) Sub(other Value) Value
- type Stringer
- type Tree
- type TreeBuilder
- type Undefined
- func (Undefined) Add(Value) Value
- func (Undefined) Divide(Value) Value
- func (u Undefined) Equal(other Undefined) bool
- func (Undefined) LShift(Value) Value
- func (Undefined) Mod(Value) Value
- func (Undefined) Multiply(Value) Value
- func (Undefined) PowerOf(Value) Value
- func (Undefined) RShift(Value) Value
- func (u Undefined) String() string
- func (Undefined) Sub(Value) Value
- type Value
- type Variable
- type Variables
Constants ¶
const Pi51199 = "" /* 51199-byte string literal not displayed */
Pi51197 returns Pi with 51197 decimal digits.
Variables ¶
This section is empty.
Functions ¶
func WithFunctions ¶
func WithFunctions(funcs Functions) treeOption
WithFunctions is a functional parameter for Tree evaluation. It provides user-defined functions.
func WithVariables ¶
func WithVariables(vars Variables) treeOption
WithVariables is a functional parameter for Tree evaluation. It provides user-defined variables.
Types ¶
type Function ¶
type Function struct { Name string BodyFn FunctionalValue Args []Tree }
func NewFunction ¶
func NewFunction(name string, bodyFn FunctionalValue, args ...Tree) Function
type FunctionalValue ¶
func PreDefinedFunction ¶
func PreDefinedFunction(name string) FunctionalValue
PreDefinedFunction returns a pre-defined function body if known. It returns `nil` when no pre-defined function exists by the specified name. This signals the Evaluator to attempt to find a user defined function.
func UserDefinedFunction ¶
func UserDefinedFunction(name string, userFunctions Functions) FunctionalValue
UserDefinedFunction is a helper function that returns the definition of the provided function name from the supplied userFunctions.
func (FunctionalValue) String ¶
func (fv FunctionalValue) String() string
type Functions ¶
type Functions map[string]FunctionalValue
Functions holds the definition of user-defined functions.
func (Functions) Function ¶
func (f Functions) Function(name string) FunctionalValue
Function returns the function definition of the function of the specified name.
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
func NewNumberFromFloat ¶
func NewNumberFromString ¶
type Tree ¶
type Tree []entry
func Parse ¶
Example: Parse("blah").Eval(WithVariables(...), WithFunctions(...)) This allows to parse an expression and then use the resulting Tree for multiple evaluations with different variables provided.
func (Tree) Calc ¶
Calc is a reduction operation that calculates the Value of sub-expressions contained in this Tree, based on operator precedence. When isOperatorInPrecedenceGroup returns true, the operator is calculated and the resultant Value is inserted in _replacement_ of the terms (elements) of this Tree that where calculated. For instance, a tree representing the expression '2 + 5 * 4 / 2' with an operator precedence of 'multiplicativeOperators' would read the Tree left to right and return a new Tree that represents: '2 + 10' where 10 was calculated (and reduced) from 5 * 4 = 20 / 2 = 10.
func (Tree) Eval ¶
Eval evaluates this tree and returns its value. It accepts optional functional parameters to supply user-defined entities such as functions and variables.
type TreeBuilder ¶
type TreeBuilder struct{}
func NewTreeBuilder ¶
func NewTreeBuilder() *TreeBuilder
type Undefined ¶
type Undefined struct {
// contains filtered or unexported fields
}
func NewUndefined ¶
func NewUndefined() Undefined
func NewUndefinedWithReasonf ¶
type Value ¶
type Value interface { Add(Value) Value Sub(Value) Value Multiply(Value) Value Divide(Value) Value PowerOf(Value) Value Mod(Value) Value LShift(Value) Value RShift(Value) Value Stringer // contains filtered or unexported methods }