Documentation ¶
Overview ¶
Package expr provides helpful conversion of mathematic expressions to base types.
The goal of this package is to behave in a similar manner to the strconv package for numerical type conversion.
It allows for code like this:
v, err := ToFloat64("1.0 + 1.0") // v == 2.0
Index ¶
- Variables
- func ToBool(s string) (bool, error)
- func ToComplex128(s string) (complex128, error)
- func ToComplex64(s string) (complex64, error)
- func ToFloat32(s string) (float32, error)
- func ToFloat64(s string) (float64, error)
- func ToInt(s string) (int, error)
- func ToInt64(s string) (int64, error)
- func ToString(s string) (string, error)
- func ToUint(s string) (uint, error)
- func ToUint64(s string) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
var ErrEvalIsUnknown = errors.New("expression is unknown")
var ErrEvalNotBool = errors.New("expression does not return a bool expression")
var ErrEvalNotComplex = errors.New("expression does not return a complex expression")
var ErrEvalNotFloat = errors.New("expression does not return a float expression")
var ErrEvalNotInt = errors.New("expression does not return an int expression")
var ErrEvalNotString = errors.New("expression does not return a string expression")
Functions ¶
func ToBool ¶
ToBool evaluates the given string as a bool, or it returns an error if the expression is Unknown.
func ToComplex128 ¶
func ToComplex128(s string) (complex128, error)
ToComplex128 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.
func ToComplex64 ¶
ToComplex64 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.
func ToFloat32 ¶
ToFloat32 evaluates the given string as a float32, or it returns an error if the result is invalid or the expression is Unknown.
func ToFloat64 ¶
ToFloat64 evaluates the given string as a float64, or it returns an error if the result is invalid or the expression is Unknown.
func ToInt ¶
ToInt evaluates the given string as an int, or it returns an error if the result is invalid or the expression is Unknown.
func ToInt64 ¶
ToInt64 evaluates the given string as an int64, or it returns an error if the result is invalid or the expression is Unknown.
func ToString ¶
ToString evaluates the given string as a string, or it returns an error if the expression is Unknown.
Types ¶
This section is empty.