Prepare for floats

This commit is contained in:
Sasha Koshka 2022-11-22 11:24:24 -05:00
parent 96468b5665
commit 31701d2fcd
1 changed files with 20 additions and 1 deletions

21
tree.go
View File

@ -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