Search in sources :

Example 1 with RealBinaryExpression

use of org.evosuite.symbolic.expr.fp.RealBinaryExpression in project evosuite by EvoSuite.

the class ATAN2 method executeFunction.

@Override
public Object executeFunction() {
    double res = this.getConcDoubleRetVal();
    RealValue left = this.getSymbRealArgument(0);
    RealValue right = this.getSymbRealArgument(1);
    RealValue atan2Expr;
    if (left.containsSymbolicVariable() || right.containsSymbolicVariable()) {
        Operator op = Operator.ATAN2;
        atan2Expr = new RealBinaryExpression(left, op, right, res);
    } else {
        atan2Expr = this.getSymbRealRetVal();
    }
    return atan2Expr;
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) Operator(org.evosuite.symbolic.expr.Operator) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Example 2 with RealBinaryExpression

use of org.evosuite.symbolic.expr.fp.RealBinaryExpression in project evosuite by EvoSuite.

the class HYPOT method executeFunction.

@Override
public Object executeFunction() {
    double res = this.getConcDoubleRetVal();
    RealValue left = this.getSymbRealArgument(0);
    RealValue right = this.getSymbRealArgument(1);
    RealValue hypotExpr;
    if (left.containsSymbolicVariable() || right.containsSymbolicVariable()) {
        Operator op = Operator.HYPOT;
        hypotExpr = new RealBinaryExpression(left, op, right, res);
    } else {
        hypotExpr = this.getSymbRealRetVal();
    }
    return hypotExpr;
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) Operator(org.evosuite.symbolic.expr.Operator) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Example 3 with RealBinaryExpression

use of org.evosuite.symbolic.expr.fp.RealBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method FSUB.

/**
 */
@Override
public void FSUB() {
    RealValue right = env.topFrame().operandStack.popFp32();
    RealValue left = env.topFrame().operandStack.popFp32();
    float left_concrete_value = ((Double) left.getConcreteValue()).floatValue();
    float right_concrete_value = ((Double) right.getConcreteValue()).floatValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewRealConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewRealConstant(right_concrete_value);
    }
    float con = left_concrete_value - right_concrete_value;
    RealValue realExpr = new RealBinaryExpression(left, Operator.MINUS, right, (double) con);
    env.topFrame().operandStack.pushFp32(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Example 4 with RealBinaryExpression

use of org.evosuite.symbolic.expr.fp.RealBinaryExpression in project evosuite by EvoSuite.

the class ExpressionFactory method buildAddNormalized.

private static RealValue buildAddNormalized(RealValue right, RealValue left, double con) {
    // can only optimize if left is a literal
    if (!(left instanceof RealConstant))
        return new RealBinaryExpression(left, Operator.PLUS, right, con);
    /*
		 * (add 0 x) --> x
		 */
    if (((RealConstant) left).getConcreteValue() == 0) {
        return right;
    }
    /*
		 * (add a b) --> result of a+b
		 */
    if (right instanceof RealConstant) {
        double a = left.getConcreteValue();
        double b = right.getConcreteValue();
        return buildNewRealConstant(a + b);
    }
    /*
		 * (add a (add b x)) --> (add (a+b) x)
		 */
    if (right instanceof RealBinaryExpression && ((RealBinaryExpression) right).getOperator() == Operator.PLUS) {
        RealBinaryExpression add = (RealBinaryExpression) right;
        if (add.getLeftOperand() instanceof RealConstant) {
            double a = left.getConcreteValue();
            double b = add.getLeftOperand().getConcreteValue();
            RealConstant a_plus_b = buildNewRealConstant(a + b);
            return new RealBinaryExpression(a_plus_b, Operator.PLUS, add.getRightOperand(), con);
        }
    }
    return new RealBinaryExpression(left, Operator.PLUS, right, con);
}
Also used : RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Example 5 with RealBinaryExpression

use of org.evosuite.symbolic.expr.fp.RealBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method DSUB.

@Override
public void DSUB() {
    RealValue right = env.topFrame().operandStack.popFp64();
    RealValue left = env.topFrame().operandStack.popFp64();
    double left_concrete_value = ((Double) left.getConcreteValue()).doubleValue();
    double right_concrete_value = ((Double) right.getConcreteValue()).doubleValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewRealConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewRealConstant(right_concrete_value);
    }
    double con = left_concrete_value - right_concrete_value;
    RealValue realExpr = new RealBinaryExpression(left, Operator.MINUS, right, con);
    env.topFrame().operandStack.pushFp64(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Aggregations

RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)9 RealValue (org.evosuite.symbolic.expr.fp.RealValue)6 Operator (org.evosuite.symbolic.expr.Operator)4 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)3 ArrayList (java.util.ArrayList)2 Constraint (org.evosuite.symbolic.expr.Constraint)2 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)2 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)2 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)2 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)2 Test (org.junit.Test)1