Documentation
¶
Index ¶
- Variables
- func CanonicalString(tokens []Token) string
- func FormatDecimal(r *big.Rat) string
- func FormatMixed(r *big.Rat) string
- type AngleMode
- type Engine
- func (e *Engine) Calculate(expression string) (*big.Rat, bool, error)
- func (e *Engine) Derive(postfixTokens []Token, xVal float64, hVal float64) (float64, error)
- func (e *Engine) EvaluateAt(postfixTokens []Token, x float64) (float64, error)
- func (e *Engine) EvaluateWithDerivative(postfixTokens []Token, x, h float64) (y, dy float64, err error)
- func (e *Engine) Parse(expression string) ([]Token, error)
- type Evaluator
- type Lexer
- type OperatorProps
- type Parser
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
InternalVars holds mathematical constants as float64. The engine converts these to *big.Rat at initialisation time. Expressions using these constants (e.g. sin(Pi)) will produce inexact results.
var OperatorPropsMap = map[string]OperatorProps{ "+": {Precedence: 2, RightAssoc: false}, "-": {Precedence: 2, RightAssoc: false}, "*": {Precedence: 3, RightAssoc: false}, "/": {Precedence: 3, RightAssoc: false}, "^": {Precedence: 4, RightAssoc: true}, "-u": {Precedence: 5, RightAssoc: true}, "sin": {Precedence: 5, RightAssoc: true}, "cos": {Precedence: 5, RightAssoc: true}, "tan": {Precedence: 5, RightAssoc: true}, }
Functions ¶
func CanonicalString ¶
func FormatDecimal ¶
FormatDecimal formats a *big.Rat as a decimal string using %g formatting, matching the previous float64 output behaviour.
func FormatMixed ¶
Types ¶
type Engine ¶
type Engine struct {
AngleMode AngleMode
// contains filtered or unexported fields
}
func (*Engine) Calculate ¶
Calculate evaluates a mathematical expression string. Returns the result as a *big.Rat, a bool indicating whether the result is exact (true = pure rational arithmetic, false = float64 approximation was used e.g. for trig functions or non-integer powers), and any error.
func (*Engine) EvaluateAt ¶
func (*Engine) EvaluateWithDerivative ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
func NewEvaluator ¶
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(postfixTokens []Token, vars map[string]*big.Rat) (*big.Rat, bool, error)
Evaluate evaluates a postfix token stream. Returns the result as a *big.Rat, a bool indicating whether the result is exact (true) or required a float64 approximation (false), and any error.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}