evaler

package
v0.0.0-...-086657b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigratToBigint

func BigratToBigint(bigrat *big.Rat) *big.Int

BigratToInt converts a *big.Rat to a *big.Int (with truncation)

func BigratToFloat

func BigratToFloat(bigrat *big.Rat) float64

BigratToFloat converts a *big.Rat to a float64 (with loss of precision).

func BigratToInt

func BigratToInt(bigrat *big.Rat) (int64, error)

BigratToInt converts a *big.Rat to an int64 (with truncation); it returns an error for integer overflows.

func Eval

func Eval(expr string) (result *big.Rat, err error)

Eval takes an infix string arithmetic expression, and evaluates it

Usage:

result, err := evaler.Eval("1+2")

Returns: the result of the evaluation, and any errors

func EvalWithVariables

func EvalWithVariables(expr string, variables map[string]string) (result *big.Rat, err error)

EvalWithVariables allows variables to be passed into expressions, for example evaluate "x + 1" where x=5

func FloatToBigrat

func FloatToBigrat(float float64) *big.Rat

FloatToBigrat converts a float64 to a *big.Rat.

func Tokenise

func Tokenise(expr string) []string

Tokenise takes an expr string and converts it to a slice of tokens

Tokenise puts spaces around all non-numbers, removes leading and trailing spaces, then splits on spaces

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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