Search in sources :

Example 1 with AviatorDecimal

use of com.googlecode.aviator.runtime.type.AviatorDecimal in project aviatorscript by killme2008.

the class MathPowFunction method call.

@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
    Number left = FunctionUtils.getNumberValue(arg1, env);
    Number right = FunctionUtils.getNumberValue(arg2, env);
    if (TypeUtils.isBigInt(left)) {
        return new AviatorBigInt(((BigInteger) left).pow(right.intValue()));
    } else if (TypeUtils.isDecimal(left)) {
        return new AviatorDecimal(((BigDecimal) left).pow(right.intValue(), RuntimeUtils.getMathContext(env)));
    } else {
        return new AviatorDouble(Math.pow(left.doubleValue(), right.doubleValue()));
    }
}
Also used : AviatorBigInt(com.googlecode.aviator.runtime.type.AviatorBigInt) AviatorDouble(com.googlecode.aviator.runtime.type.AviatorDouble) BigDecimal(java.math.BigDecimal) AviatorDecimal(com.googlecode.aviator.runtime.type.AviatorDecimal)

Aggregations

AviatorBigInt (com.googlecode.aviator.runtime.type.AviatorBigInt)1 AviatorDecimal (com.googlecode.aviator.runtime.type.AviatorDecimal)1 AviatorDouble (com.googlecode.aviator.runtime.type.AviatorDouble)1 BigDecimal (java.math.BigDecimal)1