calculator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the mathematical logic part of the calculator.

func NewEngine

func NewEngine() *Engine

NewEngine initialises an engine instance and returns it.

func (*Engine) Add

func (e *Engine) Add(x, y float64) (*float64, error)

Add is the function that processes the addition operation

func (*Engine) Div

func (e *Engine) Div(x, y float64) (*float64, error)

Div is the function that processes the divide operation

func (*Engine) GetNumOperands

func (e *Engine) GetNumOperands() int

GetNumOperands returns the expected number of operands that the engine can process.

func (*Engine) GetValidOperators

func (e *Engine) GetValidOperators() []string

GetValidOperators returns a slice of the valid operations that the engine accepts.

func (*Engine) Mult

func (e *Engine) Mult(x, y float64) (*float64, error)

Sub is the function that processes the subtract operation

func (*Engine) ProcessOperation

func (e *Engine) ProcessOperation(operation Operation) (*string, error)

ProcessOperation processes a given operation and invokes the result formatter

func (*Engine) Sub

func (e *Engine) Sub(x, y float64) (*float64, error)

Sub is the function that processes the subtract operation

type Operation

type Operation struct {
	Expression string
	Operator   string
	Operands   []float64
}

Operation is the wrapper object that contains the operator and operand of a mathematical expression.

Jump to

Keyboard shortcuts

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