Search in sources :

Example 1 with AviatorDouble

use of com.googlecode.aviator.runtime.type.AviatorDouble 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)

Example 2 with AviatorDouble

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

the class RandomFunctionUnitTest method testCall.

@Test
public void testCall() {
    RandomFunction rand = new RandomFunction();
    AviatorObject result = rand.call(null);
    assertTrue(result instanceof AviatorDouble);
    assertFalse(result.getValue(null).equals(rand.call(null)));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorDouble(com.googlecode.aviator.runtime.type.AviatorDouble) Test(org.junit.Test)

Aggregations

AviatorDouble (com.googlecode.aviator.runtime.type.AviatorDouble)2 AviatorBigInt (com.googlecode.aviator.runtime.type.AviatorBigInt)1 AviatorDecimal (com.googlecode.aviator.runtime.type.AviatorDecimal)1 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.Test)1