Prepare for floats
This commit is contained in:
parent
96468b5665
commit
31701d2fcd
21
tree.go
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user