diff --git a/calculate.go b/calculate.go index 70655db..3c50b24 100644 --- a/calculate.go +++ b/calculate.go @@ -183,7 +183,6 @@ func (operation *Operation) solution () (solution int64, err error) { func (operation *Operation) inexactSolution () (solution float64, err error) { var subSolution float64 - var rawSolution uint64 switch operation.opcode { case OpcodeAdd: @@ -271,88 +270,10 @@ func (operation *Operation) inexactSolution () (solution float64, err error) { } } - case OpcodeOr: - for _, operand := range operation.operands { - subSolution, err = operand.InexactSolution() - if err != nil { return } - rawSolution |= math.Float64bits(subSolution) - } - solution = math.Float64frombits(rawSolution) - - case OpcodeNot: - if len(operation.operands) != 1 { - err = ErrorWrongOperandCount - return - } - - subSolution, err = operation.operands[0].InexactSolution() - solution = math.Float64frombits(^math.Float64bits(subSolution)) - - case OpcodeAnd: - for index, operand := range operation.operands { - subSolution, err = operand.InexactSolution() - if err != nil { return } - if index == 0 { - rawSolution = math.Float64bits(subSolution) - } else { - rawSolution &= math.Float64bits(subSolution) - } - } - solution = math.Float64frombits(rawSolution) - - case OpcodeXor: - for index, operand := range operation.operands { - subSolution, err = operand.InexactSolution() - if err != nil { return } - if index == 0 { - rawSolution = math.Float64bits(subSolution) - } else { - rawSolution ^= math.Float64bits(subSolution) - } - } - solution = math.Float64frombits(rawSolution) - - case OpcodeLeftShift: - if len(operation.operands) != 2 { - err = ErrorWrongOperandCount - return - } - - var left, right float64 - left, err = operation.operands[0].InexactSolution() - if err != nil { return } - right, err = operation.operands[1].InexactSolution() - if err != nil { return } - - if right < 0 { - err = ErrorNegativeShiftAmount - return - } - - solution = math.Float64frombits ( - math.Float64bits(left) << - math.Float64bits(right)) - - case OpcodeRightShift: - if len(operation.operands) != 2 { - err = ErrorWrongOperandCount - return - } - - var left, right float64 - left, err = operation.operands[0].InexactSolution() - if err != nil { return } - right, err = operation.operands[1].InexactSolution() - if err != nil { return } - - if right < 0 { - err = ErrorNegativeShiftAmount - return - } - - solution = math.Float64frombits ( - math.Float64bits(left) >> - math.Float64bits(right)) + case + OpcodeOr, OpcodeNot, OpcodeAnd, OpcodeXor, OpcodeLeftShift, + OpcodeRightShift: + err = ErrorWrongType case OpcodeMean: if len(operation.operands) == 0 { break }