/*
 * Copyright 2014 Davor Sauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.jdice.calc.operation;

import java.math.BigDecimal;

import org.jdice.calc.AbstractCalculator;
import org.jdice.calc.Num;
import org.jdice.calc.Operator;

/**
 * 
 * @author Davor Sauer <davor.sauer@gmail.com>
 *
 */
public class PowOperator implements Operator {

    @Override
    public int getPriority() {
        return 15;
    }

    @Override
    public String getSymbol() {
        return "^";
    }

    @Override
    public Num calc(AbstractCalculator calc, Num value1, Num value2)  {
        BigDecimal value = value1.toBigDecimal().pow(value2.toBigDecimal().intValue());
        Num result = new Num(value);
        return result;
    }

    @Override
    public String toString() {
        return getSymbol();
    }
}

@@ -666,17 +666,18 @@
 ecimal;%0A
+%0D
 %0A
-
 import o
@@ -768,16 +768,84 @@
 perator;
+%0Aimport org.jdice.calc.Properties;%0D%0Aimport org.jdice.calc.Rounding;%0D
 %0A%0D%0A/**%0D%0A
@@ -1176,18 +1176,365 @@
 Num 
-value2
+exponent)  %7B%0D%0A        int scale = Properties.getInheritedScale(calc, exponent);%0D%0A        Rounding roundingMode = Properties.getInheritedRoundingMode(calc, exponent);%0D%0A%0D%0A        return calc(calc, value1, exponent, scale, roundingMode);%0D%0A    %7D%0D%0A%0D%0A    public Num calc(AbstractCalculator calc, Num value1, Num exponent, Integer scale, Rounding roundingMode
 )  %7B
+%0D
 %0A   
@@ -1542,59 +1542,720 @@
     
-BigDecimal value = value1.toBigDecimal().pow(value2
+if (exponent.hasFraction()) %7B%0D%0A            double result = Math.pow(value1.doubleValue(), exponent.doubleValue());%0D%0A            return new Num(result);%0D%0A        %7D else %7B%0D%0A            int ex = exponent.intValue();%0D%0A            %0D%0A            if (ex == 0)%0D%0A                return value1;%0D%0A            else if (ex %3C 0) %7B%0D%0A                BigDecimal one = BigDecimal.ONE;%0D%0A                BigDecimal value = value1.toBigDecimal().pow(ex * -1);%0D%0A                value = one.divide(value, scale, roundingMode.getBigDecimalRound());%0D%0A                %0D%0A                Num result = new Num(value);%0D%0A                return result;%0D%0A            %7D else %7B%0A                BigDecimal value = value1.toBigDecimal().pow(exponent
 .toB
@@ -2278,25 +2278,28 @@
 alue());
-%0A
+%0D%0A  
         
 Num resu
@@ -2282,32 +2282,38 @@
 ());%0D%0A          
+      
 Num result = new
@@ -2324,25 +2324,27 @@
 (value);
-%0A
+%0D%0A 
         
 return r
@@ -2327,32 +2327,39 @@
 lue);%0D%0A         
+       
 return result;%0A 
@@ -2356,16 +2356,50 @@
  result;
+%0D%0A            %7D%0A        %7D%0A        
 %0A    %7D%0A%0A

Update PowOpetaror logic to enable power with decimal and negative numbers