parsefloat

package module
v0.0.0-...-4a376ad Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2016 License: MIT Imports: 9 Imported by: 2

README

parsefloat

Go Float64 Expression Parsing Library

Build Status Coverage Status Go Report Card GoDoc

parsefloat can generate Eval-able expressions by parsing strings that contain float64's, named variables, operations of float64's, and functions of the go math library that operate on float64.

Documentation

Overview

Package parsefloat converts a string in go expression format into a reverse polish notation representation of its mathematical transformation, as long as it only has float64's, functions of float64 from the math package, and predefined identifiers.

Doing this in RPN might be kind of dumb. There may be a better way of evaluating go expressions.

Note that only functions of float64s and float64 literals are allowed, with the expection of << and >>, because while those functions can be applied to float64's, it will panic if the amount to shift is not an integer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NamedVars

func NamedVars(re *regexp.Regexp) map[string]struct{}

NamedVars returns the set of named variables within a regular expression.

Types

type Expression

type Expression interface {
	String() string
	Eval(map[string]float64) float64
}

Expression is an expression containing only float64s and functions of float64s that can be evaluated given a set of variables.

func New

func New(expr string, varNames map[string]struct{}) (Expression, error)

New Expression from a string and set of variable names. Use NamedVars to create the set.

func NewSlice

func NewSlice(expr string, varNames map[string]struct{}) ([]Expression, error)

NewSlice parses an expression representing a []float64. The input expr should begin with "float64{" and end with "}"

Jump to

Keyboard shortcuts

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