public void Visit(PowExpr powExpr, object[] args) { powExpr.FirstOp.Accept(this); powExpr.SecondOp.Accept(this); RightValue v1 = readRightValue(powExpr.FirstOp); RightValue v2 = readRightValue(powExpr.SecondOp); DataType resultType = readAlgoOperand(v1, v2, powExpr.Location); if (resultType == DataType.Int) { IntConst result = new IntConst(); result.Value = (int)Math.Pow(Convert.ToInt32(v1.GetValueObject()), Convert.ToInt32(v2.GetValueObject())); powExpr.RightValue = result; //powExpr.DataType = DataType.Int; } else if (resultType == DataType.Float) { FloatConst result = new FloatConst(); result.Value = Math.Pow(Convert.ToDouble(v1.GetValueObject()), Convert.ToDouble(v2.GetValueObject())); powExpr.RightValue = result; //powExpr.DataType = DataType.Float; } else { throw new Exception(); } }
public Value Visit(PowExpr expr, Scope scope) { return(PerformOperation(expr.Left.Accept(this, scope), expr.Right.Accept(this, scope), (a, b) => Math.Pow(a, b), (a, b) => Math.Pow(a, b), (a, b) => { throw new InvalidOperationException(); }, (a, b) => { throw new InvalidOperationException(); })); }
public string Visit(PowExpr expr, Scope scope) { return(expr.Left.Accept(this, scope) + "^" + expr.Right.Accept(this, scope)); }
public ValueType Visit(PowExpr expr, Scope scope) { return(BinaryOperatorTypeCheck(expr, scope, numericTypesOnly: true)); }