Merge pull request #820 from brendanzagaeski/master
[mono.git] / mcs / mcs / cfold.cs
index ada59bc665bf44998b41efc4a35fe46576252532..bea0ee06df05bf7a2e542eacd6dd617bccbb801a 100644 (file)
@@ -6,7 +6,7 @@
 //   Marek Safar (marek.safar@seznam.cz)
 //
 // Copyright 2002, 2003 Ximian, Inc.
-// Copyright 2003-2008, Novell, Inc.
+// Copyright 2003-2011, Novell, Inc.
 // 
 using System;
 
@@ -149,7 +149,7 @@ namespace Mono.CSharp {
                                        case Binary.Operator.ExclusiveOr:
                                                result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
                                                if (result != null)
-                                                       result = result.TryReduce (ec, lt, loc);
+                                                       result = result.Reduce (ec, lt);
                                                return result;
 
                                        ///
@@ -158,7 +158,7 @@ namespace Mono.CSharp {
                                        case Binary.Operator.Subtraction:
                                                result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
                                                if (result != null)
-                                                       result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt), loc);
+                                                       result = result.Reduce (ec, EnumSpec.GetUnderlyingType (lt));
                                                return result;
 
                                        ///
@@ -183,11 +183,11 @@ namespace Mono.CSharp {
                        switch (oper){
                        case Binary.Operator.BitwiseOr:
                                //
-                               // bool? operator &(bool? x, bool? y);
+                               // bool? operator |(bool? x, bool? y);
                                //
                                if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
                                        (rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
-                                       var b = new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                       var b = new Binary (oper, left, right).ResolveOperator (ec);
 
                                        // false | null => null
                                        // null | false => null
@@ -231,7 +231,7 @@ namespace Mono.CSharp {
                                //
                                if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
                                        (rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
-                                       var b = new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                       var b = new Binary (oper, left, right).ResolveOperator (ec);
 
                                        // false & null => false
                                        // null & false => false
@@ -299,25 +299,51 @@ namespace Mono.CSharp {
                                break;
 
                        case Binary.Operator.Addition:
-                               if (lt == InternalType.NullLiteral)
-                                       return right;
-
-                               if (rt == InternalType.NullLiteral)
-                                       return left;
-
                                //
-                               // If both sides are strings, then concatenate, if
-                               // one is a string, and the other is not, then defer
-                               // to runtime concatenation
+                               // If both sides are strings, then concatenate
+                               //
+                               // string operator + (string x, string y)
                                //
                                if (lt.BuiltinType == BuiltinTypeSpec.Type.String || rt.BuiltinType == BuiltinTypeSpec.Type.String){
                                        if (lt == rt)
                                                return new StringConstant (ec.BuiltinTypes, (string)left.GetValue () + (string)right.GetValue (),
                                                        left.Location);
-                                       
+
+                                       if (lt == InternalType.NullLiteral)
+                                               return new StringConstant (ec.BuiltinTypes, "" + right.GetValue (), left.Location);
+
+                                       if (rt == InternalType.NullLiteral)
+                                               return new StringConstant (ec.BuiltinTypes, left.GetValue () + "", left.Location);
+
                                        return null;
                                }
 
+                               //
+                               // string operator + (string x, object y)
+                               //
+                               if (lt == InternalType.NullLiteral) {
+                                       if (rt.BuiltinType == BuiltinTypeSpec.Type.Object)
+                                               return new StringConstant (ec.BuiltinTypes, "" + right.GetValue (), left.Location);
+
+                                       if (lt == rt) {
+                                               ec.Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'",
+                                                       "+", lt.GetSignatureForError (), rt.GetSignatureForError ());
+                                               return null;
+                                       }
+
+                                       return right;
+                               }
+
+                               //
+                               // string operator + (object x, string y)
+                               //
+                               if (rt == InternalType.NullLiteral) {
+                                       if (lt.BuiltinType == BuiltinTypeSpec.Type.Object)
+                                               return new StringConstant (ec.BuiltinTypes, right.GetValue () + "", left.Location);
+       
+                                       return left;
+                               }
+
                                //
                                // handle "E operator + (E x, U y)"
                                // handle "E operator + (Y y, E x)"
@@ -340,7 +366,7 @@ namespace Mono.CSharp {
                                        if (result == null)
                                                return null;
 
-                                       result = result.TryReduce (ec, lt, loc);
+                                       result = result.Reduce (ec, lt);
                                        if (result == null)
                                                return null;
 
@@ -364,14 +390,14 @@ namespace Mono.CSharp {
                                                return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
                                        }
                                        if (left is FloatConstant){
-                                               float res;
-                                               
+                                               double a, b, res;
+                                               a = ((FloatConstant) left).DoubleValue;
+                                               b = ((FloatConstant) right).DoubleValue;
+
                                                if (ec.ConstantCheckState)
-                                                       res = checked (((FloatConstant) left).Value +
-                                                                      ((FloatConstant) right).Value);
+                                                       res = checked (a + b);
                                                else
-                                                       res = unchecked (((FloatConstant) left).Value +
-                                                                        ((FloatConstant) right).Value);
+                                                       res = unchecked (a + b);
 
                                                result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is ULongConstant){
@@ -459,7 +485,7 @@ namespace Mono.CSharp {
                                        if (result == null)
                                                return null;
 
-                                       result = result.TryReduce (ec, lt, loc);
+                                       result = result.Reduce (ec, lt);
                                        if (result == null)
                                                return null;
 
@@ -467,8 +493,9 @@ namespace Mono.CSharp {
                                }
 
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                if (!DoBinaryNumericPromotions (ec, ref left, ref right))
@@ -487,14 +514,14 @@ namespace Mono.CSharp {
 
                                                result = new DoubleConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is FloatConstant){
-                                               float res;
-                                               
+                                               double a, b, res;
+                                               a = ((FloatConstant) left).DoubleValue;
+                                               b = ((FloatConstant) right).DoubleValue;
+
                                                if (ec.ConstantCheckState)
-                                                       res = checked (((FloatConstant) left).Value -
-                                                                      ((FloatConstant) right).Value);
+                                                       res = checked (a - b);
                                                else
-                                                       res = unchecked (((FloatConstant) left).Value -
-                                                                        ((FloatConstant) right).Value);
+                                                       res = unchecked (a - b);
 
                                                result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is ULongConstant){
@@ -563,8 +590,9 @@ namespace Mono.CSharp {
                                
                        case Binary.Operator.Multiply:
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                if (!DoBinaryNumericPromotions (ec, ref left, ref right))
@@ -583,14 +611,14 @@ namespace Mono.CSharp {
 
                                                return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is FloatConstant){
-                                               float res;
-                                               
+                                               double a, b, res;
+                                               a = ((FloatConstant) left).DoubleValue;
+                                               b = ((FloatConstant) right).DoubleValue;
+
                                                if (ec.ConstantCheckState)
-                                                       res = checked (((FloatConstant) left).Value *
-                                                               ((FloatConstant) right).Value);
+                                                       res = checked (a * b);
                                                else
-                                                       res = unchecked (((FloatConstant) left).Value *
-                                                               ((FloatConstant) right).Value);
+                                                       res = unchecked (a * b);
 
                                                return new FloatConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is ULongConstant){
@@ -658,8 +686,9 @@ namespace Mono.CSharp {
 
                        case Binary.Operator.Division:
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                if (!DoBinaryNumericPromotions (ec, ref left, ref right))
@@ -678,14 +707,14 @@ namespace Mono.CSharp {
 
                                                return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is FloatConstant){
-                                               float res;
-                                               
+                                               double a, b, res;
+                                               a = ((FloatConstant) left).DoubleValue;
+                                               b = ((FloatConstant) right).DoubleValue;
+
                                                if (ec.ConstantCheckState)
-                                                       res = checked (((FloatConstant) left).Value /
-                                                               ((FloatConstant) right).Value);
+                                                       res = checked (a / b);
                                                else
-                                                       res = unchecked (((FloatConstant) left).Value /
-                                                               ((FloatConstant) right).Value);
+                                                       res = unchecked (a / b);
 
                                                return new FloatConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is ULongConstant){
@@ -757,8 +786,9 @@ namespace Mono.CSharp {
                                
                        case Binary.Operator.Modulus:
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                if (!DoBinaryNumericPromotions (ec, ref left, ref right))
@@ -777,14 +807,14 @@ namespace Mono.CSharp {
 
                                                return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is FloatConstant){
-                                               float res;
+                                               double a, b, res;
+                                               a = ((FloatConstant) left).DoubleValue;
+                                               b = ((FloatConstant) right).DoubleValue;
                                                
                                                if (ec.ConstantCheckState)
-                                                       res = checked (((FloatConstant) left).Value %
-                                                                      ((FloatConstant) right).Value);
+                                                       res = checked (a % b);
                                                else
-                                                       res = unchecked (((FloatConstant) left).Value %
-                                                                        ((FloatConstant) right).Value);
+                                                       res = unchecked (a % b);
 
                                                return new FloatConstant (ec.BuiltinTypes, res, left.Location);
                                        } else if (left is ULongConstant){
@@ -846,13 +876,13 @@ namespace Mono.CSharp {
                                //
                        case Binary.Operator.LeftShift:
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                IntConstant ic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
                                if (ic == null){
-                                       Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
                                        return null;
                                }
 
@@ -868,27 +898,26 @@ namespace Mono.CSharp {
 
                                // null << value => null
                                if (left is NullLiteral)
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                       return (Constant) new Binary (oper, left, right).ResolveOperator (ec);
 
                                left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
                                if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
                                        return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value << lshift_val, left.Location);
 
-                               Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
-                               break;
+                               return null;
 
                                //
                                // There is no overflow checking on right shift
                                //
                        case Binary.Operator.RightShift:
                                if (left is NullLiteral && right is NullLiteral) {
-                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+                                       var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                       lifted_int.ResolveAsType (ec);
+                                       return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                }
 
                                IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
                                if (sic == null){
-                                       Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
                                        return null;
                                }
                                int rshift_val = sic.Value;
@@ -903,23 +932,22 @@ namespace Mono.CSharp {
 
                                // null >> value => null
                                if (left is NullLiteral)
-                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                       return (Constant) new Binary (oper, left, right).ResolveOperator (ec);
 
                                left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
                                if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
                                        return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value >> rshift_val, left.Location);
 
-                               Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
-                               break;
+                               return null;
 
                        case Binary.Operator.Equality:
-                               if (TypeManager.IsReferenceType (lt) && TypeManager.IsReferenceType (rt) ||
+                               if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
                                        (left is Nullable.LiftedNull && right.IsNull) ||
                                        (right is Nullable.LiftedNull && left.IsNull)) {
                                        if (left.IsNull || right.IsNull) {
                                                return ReducedExpression.Create (
                                                        new BoolConstant (ec.BuiltinTypes, left.IsNull == right.IsNull, left.Location),
-                                                       new Binary (oper, left, right, loc));
+                                                       new Binary (oper, left, right));
                                        }
 
                                        if (left is StringConstant && right is StringConstant)
@@ -937,8 +965,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value ==
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value ==
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue ==
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value ==
                                                ((ULongConstant) right).Value;
@@ -957,13 +985,13 @@ namespace Mono.CSharp {
                                return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
 
                        case Binary.Operator.Inequality:
-                               if (TypeManager.IsReferenceType (lt) && TypeManager.IsReferenceType (rt) ||
+                               if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
                                        (left is Nullable.LiftedNull && right.IsNull) ||
                                        (right is Nullable.LiftedNull && left.IsNull)) {
                                        if (left.IsNull || right.IsNull) {
                                                return ReducedExpression.Create (
                                                        new BoolConstant (ec.BuiltinTypes, left.IsNull != right.IsNull, left.Location),
-                                                       new Binary (oper, left, right, loc));
+                                                       new Binary (oper, left, right));
                                        }
 
                                        if (left is StringConstant && right is StringConstant)
@@ -981,8 +1009,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value !=
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value !=
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue !=
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value !=
                                                ((ULongConstant) right).Value;
@@ -1003,12 +1031,9 @@ namespace Mono.CSharp {
                        case Binary.Operator.LessThan:
                                if (right is NullLiteral) {
                                        if (left is NullLiteral) {
-                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
-                                       }
-
-                                       if (left is Nullable.LiftedNull) {
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                               lifted_int.ResolveAsType (ec);
+                                               return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                        }
                                }
 
@@ -1020,8 +1045,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value <
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value <
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue <
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value <
                                                ((ULongConstant) right).Value;
@@ -1042,12 +1067,9 @@ namespace Mono.CSharp {
                        case Binary.Operator.GreaterThan:
                                if (right is NullLiteral) {
                                        if (left is NullLiteral) {
-                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
-                                       }
-
-                                       if (left is Nullable.LiftedNull) {
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                               lifted_int.ResolveAsType (ec);
+                                               return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                        }
                                }
 
@@ -1059,8 +1081,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value >
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value >
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue >
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value >
                                                ((ULongConstant) right).Value;
@@ -1081,12 +1103,9 @@ namespace Mono.CSharp {
                        case Binary.Operator.GreaterThanOrEqual:
                                if (right is NullLiteral) {
                                        if (left is NullLiteral) {
-                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
-                                       }
-
-                                       if (left is Nullable.LiftedNull) {
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                               lifted_int.ResolveAsType (ec);
+                                               return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                        }
                                }
 
@@ -1098,8 +1117,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value >=
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value >=
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue >=
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value >=
                                                ((ULongConstant) right).Value;
@@ -1120,12 +1139,9 @@ namespace Mono.CSharp {
                        case Binary.Operator.LessThanOrEqual:
                                if (right is NullLiteral) {
                                        if (left is NullLiteral) {
-                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
-                                       }
-
-                                       if (left is Nullable.LiftedNull) {
-                                               return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+                                               var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+                                               lifted_int.ResolveAsType (ec);
+                                               return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
                                        }
                                }
 
@@ -1137,8 +1153,8 @@ namespace Mono.CSharp {
                                        bool_res = ((DoubleConstant) left).Value <=
                                                ((DoubleConstant) right).Value;
                                else if (left is FloatConstant)
-                                       bool_res = ((FloatConstant) left).Value <=
-                                               ((FloatConstant) right).Value;
+                                       bool_res = ((FloatConstant) left).DoubleValue <=
+                                               ((FloatConstant) right).DoubleValue;
                                else if (left is ULongConstant)
                                        bool_res = ((ULongConstant) left).Value <=
                                                ((ULongConstant) right).Value;
@@ -1156,7 +1172,7 @@ namespace Mono.CSharp {
 
                                return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
                        }
-                                       
+
                        return null;
                }
        }