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)
|
Previous () (previous Expression)
|
||||||
Render (target stone.Buffer, offset int) (moved int)
|
Render (target stone.Buffer, offset int) (moved int)
|
||||||
Solution () (solution int64, err error)
|
Solution () (solution int64, err error)
|
||||||
// InexactSolution () (solution float64, err error)
|
InexactSolution () (solution float64, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Operation struct {
|
type Operation struct {
|
||||||
parent *Operation
|
parent *Operation
|
||||||
opcode Opcode
|
opcode Opcode
|
||||||
operands []Expression
|
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) {
|
func (operation *Operation) Parent () (parent *Operation) {
|
||||||
@ -406,6 +418,13 @@ func (operation *Operation) Solution () (solution int64, err error) {
|
|||||||
return
|
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) {
|
func integerPower (x, y int64) (result int64) {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
result = 1
|
result = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user