static LiteralExpression GetFoldedDoubleLiteral(BinaryOperatorType @operator, double lhs, double rhs)
{
double result;
switch (@operator)
{
//arithmetic
case BinaryOperatorType.Addition:
result = lhs + rhs;
break;
case BinaryOperatorType.Subtraction:
result = lhs - rhs;
break;
case BinaryOperatorType.Multiply:
result = lhs * rhs;
break;
case BinaryOperatorType.Division:
result = lhs / rhs;
break;
case BinaryOperatorType.Modulus:
result = lhs % rhs;
break;
case BinaryOperatorType.Exponentiation:
result = Math.Pow(lhs, rhs);
break;
//comparison
case BinaryOperatorType.LessThan:
return new BoolLiteralExpression(lhs < rhs);
case BinaryOperatorType.LessThanOrEqual:
return new BoolLiteralExpression(lhs <= rhs);
case BinaryOperatorType.GreaterThan:
return new BoolLiteralExpression(lhs > rhs);
case BinaryOperatorType.GreaterThanOrEqual:
return new BoolLiteralExpression(lhs >= rhs);
case BinaryOperatorType.Equality:
return new BoolLiteralExpression(lhs == rhs);
case BinaryOperatorType.Inequality:
return new BoolLiteralExpression(lhs != rhs);
default:
return null; //not supported
}
return new DoubleLiteralExpression(result);
}