Fixed root operator

For some reason I thought that negative exponents gave roots and
not fractional ones.
This commit is contained in:
Sasha Koshka 2022-11-22 01:34:09 -05:00
parent 729ea8d48d
commit 96468b5665
1 changed files with 8 additions and 5 deletions

13
tree.go
View File

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