martykan/ivs-calculator

Math library interface, exception handling (2)

Closed this issue · 3 comments

func Eval(input string) (float64, error)

type SyntaxError struct {
    index int
}
func (se *SyntaxError) Error() string {
    return fmt.Sprintf("Invalid syntax at index: %d.", se.index)
}

func Parse(input string) (*TreeNode, error) // can return the index of invalid syntax, so that it can be highlighted in the GUI
func Interpret(root *TreeNode) (float64, error)

// Basic math operations
func Add(a float64, b float64) float64
func Substract(a float64, b float64) float64
func Multiply(a float64, b float64) float64
func Divide(a float64, b float64) (float64, error) // b != 0

// Advanced math operations
func Modulo(a float64, b float64) (float64, error) // b != 0
func AbsoluteValue(a float64) float64 
func Factorial(a float64) (float64, error) // a has to be an integer - could return an error, or round
func Power(base float64, exponent float64) (float64, error) // exponent has to be a natural number (including 0?)
func Root(x float64, n float64) (float64, error) // 

Should we mark this done?

Ideally the code should be commited to the repo

Ok, I will put the function stubs into the respective files and commit it