diff --git a/tree.go b/tree.go index ab5296f..065080c 100644 --- a/tree.go +++ b/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