コード例 #1
0
        ISemantic HandleSingleMathOp(OperatorBasedExpression x, ISemantic l, ISemantic r, MathOp2 m, bool UnorderedCheck = true)
        {
            if (l == null || r == null)
            {
                return(null);
            }

            var pl = l as PrimitiveValue;
            var pr = r as PrimitiveValue;

            //TODO: imaginary/complex parts

            if (pl != null && pr != null)
            {
                if (UnorderedCheck && (pl.IsNaN || pr.IsNaN))
                {
                    return(PrimitiveValue.CreateNaNValue(x, pl.IsNaN ? pl.BaseTypeToken : pr.BaseTypeToken));
                }

                return(m(pl, pr, x));
            }

            throw new NotImplementedException("Operator overloading not implemented yet.");
        }
コード例 #2
0
		bool EnsureIntegralType(IExpression x,PrimitiveValue v)
		{
			if (!DTokens.BasicTypes_Integral[v.BaseTypeToken]){
				EvalError(x,"Literal must be of integral type",new[]{(ISemantic)v});
				return false;
			}
			return true;
		}
コード例 #3
0
		static PrimitiveValue mult(PrimitiveValue a, PrimitiveValue b, OperatorBasedExpression x)
		{
			decimal v = 0;
			decimal im=0;
			switch (x.OperatorToken)
			{
				case DTokens.Pow:
					v = (decimal)Math.Pow((double)a.Value, (double)b.Value);
					v = (decimal)Math.Pow((double)a.ImaginaryPart, (double)b.ImaginaryPart);
					break;
				case DTokens.Times:
					v= a.Value * b.Value;
					im=a.ImaginaryPart * b.ImaginaryPart;
					break;
				case DTokens.Div:
					if ((a.Value!=0 && b.Value == 0) || (a.ImaginaryPart!=0 && b.ImaginaryPart==0))
						throw new DivideByZeroException();
					if(b.Value!=0)
						v= a.Value / b.Value;
					if(b.ImaginaryPart!=0)
						im=a.ImaginaryPart / b.ImaginaryPart;
					break;
				case DTokens.Mod:
					if ((a.Value!=0 && b.Value == 0) || (a.ImaginaryPart!=0 && b.ImaginaryPart==0))
						throw new DivideByZeroException();
					if(b.Value!=0)
						v= a.Value % b.Value;
					if(b.ImaginaryPart!=0)
						im=a.ImaginaryPart % b.ImaginaryPart;
					break;
				default:
					return null;
					//EvalError(x, "Invalid token for multiplication expression (*,/,% only)");
			}

			return new PrimitiveValue(a.BaseTypeToken, v, x, im);
		}