Beispiel #1
0
        internal override ElaValue Divide(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                    return new ElaValue(left.DirectGetSingle() / right.Ref.AsDouble());
                else if (right.TypeId == ElaMachine.INT)
                    return new ElaValue(left.DirectGetSingle() / right.I4);
                else if (right.TypeId == ElaMachine.LNG)
                    return new ElaValue(left.DirectGetSingle() / right.Ref.AsLong());
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "divide", ctx);
                    return Default();
                }
            }

            if (right.DirectGetSingle() == 0)
            {
                ctx.DivideByZero(left);
                return Default();
            }

            return new ElaValue(left.DirectGetSingle() / right.DirectGetSingle());
        }
Beispiel #2
0
        internal override ElaValue Modulus(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                {
                    return(DoubleInstance.Modulus(left.DirectGetSingle(), right.Ref.AsDouble(), ctx));
                }
                else if (right.TypeId == ElaMachine.INT)
                {
                    return(Modulus(left.DirectGetSingle(), right.I4, ctx));
                }
                else if (right.TypeId == ElaMachine.LNG)
                {
                    return(Modulus(left.DirectGetSingle(), right.Ref.AsLong(), ctx));
                }
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "modulus", ctx);
                    return(Default());
                }
            }

            return(Modulus(left.DirectGetSingle(), right.DirectGetSingle(), ctx));
        }
Beispiel #3
0
        internal override bool Greater(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                {
                    return(left.DirectGetSingle() > right.Ref.AsDouble());
                }
                else if (right.TypeId == ElaMachine.INT)
                {
                    return(left.DirectGetSingle() > right.I4);
                }
                else if (right.TypeId == ElaMachine.LNG)
                {
                    return(left.DirectGetSingle() > right.Ref.AsLong());
                }
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "greater", ctx);
                    return(false);
                }
            }

            return(left.DirectGetSingle() > right.DirectGetSingle());
        }
Beispiel #4
0
        internal override ElaValue Power(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                {
                    return(new ElaValue(Math.Pow(left.DirectGetSingle(), right.Ref.AsDouble())));
                }
                else if (right.TypeId == ElaMachine.INT)
                {
                    return(new ElaValue((Single)Math.Pow(left.DirectGetSingle(), right.I4)));
                }
                else if (right.TypeId == ElaMachine.LNG)
                {
                    return(new ElaValue((Single)Math.Pow(left.DirectGetSingle(), right.Ref.AsLong())));
                }
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "power", ctx);
                    return(Default());
                }
            }

            return(new ElaValue(Math.Pow(left.DirectGetSingle(), right.DirectGetSingle())));
        }
Beispiel #5
0
        internal override ElaValue Remainder(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                {
                    return(new ElaValue(left.DirectGetSingle() % right.Ref.AsDouble()));
                }
                else if (right.TypeId == ElaMachine.INT)
                {
                    return(new ElaValue(left.DirectGetSingle() % right.I4));
                }
                else if (right.TypeId == ElaMachine.LNG)
                {
                    return(new ElaValue(left.DirectGetSingle() % right.Ref.AsLong()));
                }
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "remainder", ctx);
                    return(Default());
                }
            }

            if (right.DirectGetSingle() == 0)
            {
                ctx.DivideByZero(left);
                return(Default());
            }

            return(new ElaValue(left.DirectGetSingle() % right.DirectGetSingle()));
        }
Beispiel #6
0
        internal override ElaValue Divide(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.INT)
            {
                if (right.TypeId == ElaMachine.LNG)
                {
                    var r = right.Ref.AsLong();
                    return(new ElaValue((Double)left.I4 / r));
                }
                else if (right.TypeId == ElaMachine.REA)
                {
                    return(new ElaValue(left.I4 / right.DirectGetSingle()));
                }
                else if (right.TypeId == ElaMachine.DBL)
                {
                    return(new ElaValue(left.I4 / right.Ref.AsDouble()));
                }
                else
                {
                    NoOverloadBinary(TCF.INT, right, "divide", ctx);
                    return(Default());
                }
            }

            return(new ElaValue((Single)left.I4 / right.I4));
        }
Beispiel #7
0
        internal override bool LesserEqual(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.INT)
            {
                if (right.TypeId == ElaMachine.LNG)
                {
                    return(left.I4 <= right.Ref.AsLong());
                }
                else if (right.TypeId == ElaMachine.REA)
                {
                    return(left.I4 <= right.DirectGetSingle());
                }
                else if (right.TypeId == ElaMachine.DBL)
                {
                    return(left.I4 <= right.Ref.AsDouble());
                }
                else
                {
                    NoOverloadBinary(TCF.INT, right, "lesserequal", ctx);
                    return(false);
                }
            }

            return(left.I4 <= right.I4);
        }
Beispiel #8
0
        internal override ElaValue Multiply(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                {
                    return(new ElaValue(left.Ref.AsLong() + right.I4));
                }
                else if (right.TypeId == ElaMachine.REA)
                {
                    return(new ElaValue(left.Ref.AsLong() + right.DirectGetSingle()));
                }
                else if (right.TypeId == ElaMachine.DBL)
                {
                    return(new ElaValue(left.Ref.AsLong() + right.Ref.AsDouble()));
                }
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "multiply", ctx);
                    return(Default());
                }
            }

            return(new ElaValue(left.Ref.AsLong() * right.Ref.AsLong()));
        }
Beispiel #9
0
        internal override ElaValue Subtract(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.DBL)
            {
                if (right.TypeId == ElaMachine.REA)
                {
                    return(new ElaValue(left.Ref.AsDouble() - right.DirectGetSingle()));
                }
                else if (right.TypeId == ElaMachine.INT)
                {
                    return(new ElaValue(left.Ref.AsDouble() - right.I4));
                }
                else if (right.TypeId == ElaMachine.LNG)
                {
                    return(new ElaValue(left.Ref.AsDouble() - right.Ref.AsLong()));
                }
                else
                {
                    NoOverloadBinary(TCF.DOUBLE, right, "subtract", ctx);
                    return(Default());
                }
            }

            return(new ElaValue(left.Ref.AsDouble() - right.Ref.AsDouble()));
        }
Beispiel #10
0
        internal override bool Equal(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.REA)
            {
                if (right.TypeId == ElaMachine.DBL)
                    return left.DirectGetSingle() == right.Ref.AsDouble();
                else if (right.TypeId == ElaMachine.INT)
                    return left.DirectGetSingle() == right.I4;
                else if (right.TypeId == ElaMachine.LNG)
                    return left.DirectGetSingle() == right.Ref.AsLong();
                else
                {
                    NoOverloadBinary(TCF.SINGLE, right, "equal", ctx);
                    return false;
                }
            }

            return left.DirectGetSingle() == right.DirectGetSingle();
        }
Beispiel #11
0
        internal override string Show(ElaValue value, ExecutionContext ctx)
        {
            var d = value.DirectGetSingle();

            if (Single.IsInfinity(d) || Single.IsNaN(d))
            {
                return(value.ToString());
            }
            else
            {
                return(value.ToString() + "f");
            }
        }
Beispiel #12
0
        internal override ElaValue Add(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                    return new ElaValue(left.Ref.AsLong() + right.I4);
                else if (right.TypeId == ElaMachine.REA)
                    return new ElaValue(left.Ref.AsLong() + right.DirectGetSingle());
                else if (right.TypeId == ElaMachine.DBL)
                    return new ElaValue(left.Ref.AsLong() + right.Ref.AsDouble());
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "add", ctx);
                    return Default();
                }
            }

            return new ElaValue(left.Ref.AsLong() + right.Ref.AsLong());
        }
Beispiel #13
0
        internal override ElaValue Power(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                    return new ElaValue((Int64)Math.Pow(left.Ref.AsLong(), right.I4));
                else if (right.TypeId == ElaMachine.REA)
                    return new ElaValue((Single)Math.Pow(left.Ref.AsLong(), right.DirectGetSingle()));
                else if (right.TypeId == ElaMachine.DBL)
                    return new ElaValue((Double)Math.Pow(left.Ref.AsLong(), right.Ref.AsDouble()));
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "power", ctx);
                    return Default();
                }
            }

            return new ElaValue((Int64)Math.Pow(left.Ref.AsLong(), right.Ref.AsLong()));
        }
Beispiel #14
0
        internal override ElaValue Modulus(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                    return Modulus(left.Ref.AsLong(), right.I4, ctx);
                else if (right.TypeId == ElaMachine.REA)
                    return SingleInstance.Modulus(left.Ref.AsLong(), right.DirectGetSingle(), ctx);
                else if (right.TypeId == ElaMachine.DBL)
                    return DoubleInstance.Modulus(left.Ref.AsLong(), right.Ref.AsDouble(), ctx);
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "modulus", ctx);
                    return Default();
                }
            }

            return Modulus(left.Ref.AsLong(), right.Ref.AsLong(), ctx);
        }
Beispiel #15
0
        internal override bool Lesser(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                    return left.Ref.AsLong() < right.I4;
                else if (right.TypeId == ElaMachine.REA)
                    return left.Ref.AsLong() < right.DirectGetSingle();
                else if (right.TypeId == ElaMachine.DBL)
                    return left.Ref.AsLong() < right.Ref.AsDouble();
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "lesser", ctx);
                    return false;
                }
            }

            return left.Ref.AsLong() < right.Ref.AsLong();
        }
Beispiel #16
0
 internal override ElaValue Negate(ElaValue value, ExecutionContext ctx)
 {
     return(new ElaValue(-value.DirectGetSingle()));
 }
Beispiel #17
0
        internal override ElaValue Remainder(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                {
                    if (right.I4 == 0)
                    {
                        ctx.DivideByZero(left);
                        return Default();
                    }

                    return new ElaValue(left.Ref.AsLong() % right.I4);
                }
                else if (right.TypeId == ElaMachine.REA)
                    return new ElaValue(left.Ref.AsLong() % right.DirectGetSingle());
                else if (right.TypeId == ElaMachine.DBL)
                    return new ElaValue(left.Ref.AsLong() % right.Ref.AsDouble());
                else
                {
                    NoOverloadBinary(TCF.LONG, right, "remainder", ctx);
                    return Default();
                }
            }

            var rl = right.Ref.AsLong();

            if (rl == 0)
            {
                ctx.DivideByZero(left);
                return Default();
            }

            return new ElaValue(left.Ref.AsLong() % rl);
        }
Beispiel #18
0
        internal override string Show(ElaValue value, ExecutionContext ctx)
        {
            var d = value.DirectGetSingle();

            if (Single.IsInfinity(d) || Single.IsNaN(d))
                return value.ToString();
            else
                return value.ToString() + "f";
        }
Beispiel #19
0
        internal override ElaValue Divide(ElaValue left, ElaValue right, ExecutionContext ctx)
        {
            if (right.TypeId != ElaMachine.LNG)
            {
                if (right.TypeId == ElaMachine.INT)
                {
                    return new ElaValue((Double)left.Ref.AsLong() / right.I4);
                }
                else if (right.TypeId == ElaMachine.REA)
                    return new ElaValue(left.Ref.AsLong() / right.DirectGetSingle());
                else if (right.TypeId == ElaMachine.DBL)
                    return new ElaValue(left.Ref.AsLong() / right.Ref.AsDouble());
                else
                {
                    NoOverloadBinary(TCF.INT, right, "divide", ctx);
                    return Default();
                }
            }

            var r = right.Ref.AsLong();
            return new ElaValue((Double)left.Ref.AsLong() / r);
        }
Beispiel #20
0
 internal override ElaValue Negate(ElaValue value, ExecutionContext ctx)
 {
     return new ElaValue(-value.DirectGetSingle());
 }