Fixed root operator
For some reason I thought that negative exponents gave roots and not fractional ones.
This commit is contained in:
parent
729ea8d48d
commit
96468b5665
13
tree.go
13
tree.go
@ -311,8 +311,8 @@ func (operation *Operation) Solution () (solution int64, err error) {
|
||||
if index == 0 {
|
||||
solution = subSolution
|
||||
} else {
|
||||
solution = integerPower (
|
||||
solution, subSolution * -1)
|
||||
solution = integerRoot (
|
||||
solution, subSolution)
|
||||
}
|
||||
}
|
||||
case OpcodeModulo:
|
||||
@ -410,9 +410,6 @@ func integerPower (x, y int64) (result int64) {
|
||||
if y == 0 {
|
||||
result = 1
|
||||
return
|
||||
} else if y < 0 {
|
||||
// FIXME: find some algorithm for the nth root of an integer
|
||||
result = int64(math.Pow(float64(x), float64(y)))
|
||||
}
|
||||
|
||||
result = x
|
||||
@ -422,6 +419,12 @@ func integerPower (x, y int64) (result int64) {
|
||||
return
|
||||
}
|
||||
|
||||
func integerRoot (x, y int64) (result int64) {
|
||||
// FIXME: find some algorithm for the nth root of an integer
|
||||
result = int64(math.Pow(float64(x), 1 / float64(y)))
|
||||
return
|
||||
}
|
||||
|
||||
type IntegerLiteral struct {
|
||||
parent *Operation
|
||||
displayRadix int
|
||||
|
Loading…
Reference in New Issue
Block a user