Merge branch 'BigIntegerParse'
[mono.git] / mcs / class / System.Numerics / System.Numerics / BigInteger.cs
index da634fdc5f4237dffe86a13942b978d6b7df9bcc..4205d8ccdca4ce8fe1b718d0546ea08550a6b9eb 100644 (file)
@@ -473,10 +473,20 @@ namespace System.Numerics {
                                return (((long)high) << 32) | low;
                        }
 
-                       if (high > 0x80000000u)
+                       /*
+                       We cannot represent negative numbers smaller than long.MinValue.
+                       Those values are encoded into what look negative numbers, so negating
+                       them produces a positive value, that's why it's safe to check for that
+                       condition.
+
+                       long.MinValue works fine since it's bigint encoding looks like a negative
+                       number, but since long.MinValue == -long.MinValue, we're good.
+                       */
+
+                       long result = - ((((long)high) << 32) | (long)low);
+                       if (result > 0)
                                throw new OverflowException ();
-
-                       return - ((((long)high) << 32) | (long)low);
+                       return result;
                }
 
                [CLSCompliantAttribute (false)]