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 {
|
if index == 0 {
|
||||||
solution = subSolution
|
solution = subSolution
|
||||||
} else {
|
} else {
|
||||||
solution = integerPower (
|
solution = integerRoot (
|
||||||
solution, subSolution * -1)
|
solution, subSolution)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case OpcodeModulo:
|
case OpcodeModulo:
|
||||||
@ -410,9 +410,6 @@ func integerPower (x, y int64) (result int64) {
|
|||||||
if y == 0 {
|
if y == 0 {
|
||||||
result = 1
|
result = 1
|
||||||
return
|
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
|
result = x
|
||||||
@ -422,6 +419,12 @@ func integerPower (x, y int64) (result int64) {
|
|||||||
return
|
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 {
|
type IntegerLiteral struct {
|
||||||
parent *Operation
|
parent *Operation
|
||||||
displayRadix int
|
displayRadix int
|
||||||
|
Loading…
Reference in New Issue
Block a user