diff --git a/tree.go b/tree.go index 065080c..3444209 100644 --- a/tree.go +++ b/tree.go @@ -57,13 +57,25 @@ type Expression interface { Previous () (previous Expression) Render (target stone.Buffer, offset int) (moved int) Solution () (solution int64, err error) - // InexactSolution () (solution float64, err error) + InexactSolution () (solution float64, err error) } type Operation struct { parent *Operation opcode Opcode operands []Expression + + // TODO: add bool to make this into a float + // when it is a float: + // - displays with parentheses instead of brackets + // - compute solution in floating point manner + // - return floating point solution for both Solution and + // InexactSolution, instead of the other way around, casting as + // necessary + // - ask children for InexactSolution instead of Solution + // + // TODO: have some control to make the readout call InexactSolution + // instead of Solution and display the floating point data properly } func (operation *Operation) Parent () (parent *Operation) { @@ -406,6 +418,13 @@ func (operation *Operation) Solution () (solution int64, err error) { return } +func (operation *Operation) InexactSolution (solution float64, err error) { + var intSolution int64 + intSolution, err = operation.Solution() + solution = float64(intSolution) + return +} + func integerPower (x, y int64) (result int64) { if y == 0 { result = 1