* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlInt64.cs
index c4a8a553a7e04603f20071e4480d8d09b8edf4d2..c9a22a2632761315544601b2914fd7f4d88db4fe 100644 (file)
@@ -3,10 +3,34 @@
 //
 // Author:
 //   Tim Coleman <tim@timcoleman.com>
+//   Ville Palo <vi64pa@koti.soon.fi>
 //
 // (C) Copyright 2002 Tim Coleman
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Globalization;
 
@@ -78,10 +102,22 @@ namespace System.Data.SqlTypes
                                return 1;
                        else if (!(value is SqlInt64))
                                throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
-                       else if (((SqlInt64)value).IsNull)
+                       return CompareSqlInt64 ((SqlInt64) value);
+               }
+
+               #if NET_2_0
+               public int CompareTo (SqlInt64 value)
+               {
+                       return CompareSqlInt64 ((SqlInt64) value);
+               }
+               #endif  
+       
+               private int CompareSqlInt64 (SqlInt64 value)
+               {
+                       if (value.IsNull)
                                return 1;
                        else
-                               return this.value.CompareTo (((SqlInt64)value).Value);
+                               return this.value.CompareTo (value.Value);
                }
 
                public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
@@ -93,6 +129,10 @@ namespace System.Data.SqlTypes
                {
                        if (!(value is SqlInt64))
                                return false;
+                       else if (this.IsNull && ((SqlInt64)value).IsNull)
+                               return true;
+                       else if (((SqlInt64)value).IsNull)
+                               return false;
                        else
                                return (bool) (this == (SqlInt64)value);
                }
@@ -132,6 +172,13 @@ namespace System.Data.SqlTypes
                        return (x % y);
                }
 
+               #if NET_2_0
+               public static SqlInt64 Modulus (SqlInt64 x, SqlInt64 y)
+               {
+                       return (x % y);
+               }
+               #endif
+
                public static SqlInt64 Multiply (SqlInt64 x, SqlInt64 y)
                {
                        return (x * y);
@@ -240,7 +287,9 @@ namespace System.Data.SqlTypes
 
                public static SqlInt64 operator / (SqlInt64 x, SqlInt64 y)
                {
-                       return new SqlInt64 (x.Value / y.Value);
+                       checked {
+                               return new SqlInt64 (x.Value / y.Value);
+                       }
                }
 
                public static SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
@@ -310,6 +359,9 @@ namespace System.Data.SqlTypes
 
                public static SqlInt64 operator ~ (SqlInt64 x)
                {
+                       if (x.IsNull)
+                               return SqlInt64.Null;
+
                        return new SqlInt64 (~(x.Value));
                }
 
@@ -335,18 +387,23 @@ namespace System.Data.SqlTypes
 
                public static explicit operator SqlInt64 (SqlDecimal x)
                {
-                       if (x.IsNull) 
-                               return SqlInt64.Null;
-                       else
-                               return new SqlInt64 ((long)x.Value);
+                       checked {
+                               if (x.IsNull) 
+                                       return SqlInt64.Null;
+                               else
+                                       return new SqlInt64 ((long)x.Value);
+                       }
                }
 
                public static explicit operator SqlInt64 (SqlDouble x)
                {
                        if (x.IsNull) 
                                return SqlInt64.Null;
-                       else
-                               return new SqlInt64 ((long)x.Value);
+                       else {
+                               checked {
+                                       return new SqlInt64 ((long)x.Value);
+                               }
+                       }
                }
 
                public static explicit operator long (SqlInt64 x)
@@ -356,23 +413,30 @@ namespace System.Data.SqlTypes
 
                public static explicit operator SqlInt64 (SqlMoney x)
                {
-                       if (x.IsNull) 
-                               return SqlInt64.Null;
-                       else
-                               return new SqlInt64 ((long)x.Value);
+                       checked {
+                               if (x.IsNull) 
+                                       return SqlInt64.Null;
+                               else
+                                       return new SqlInt64 ((long) Math.Round (x.Value));
+                       }
                }
 
                public static explicit operator SqlInt64 (SqlSingle x)
                {
                        if (x.IsNull) 
                                return SqlInt64.Null;
-                       else
-                               return new SqlInt64 ((long)x.Value);
+                       else {
+                               checked {
+                                       return new SqlInt64 ((long)x.Value);
+                               }
+                       }
                }
 
                public static explicit operator SqlInt64 (SqlString x)
                {
-                       return SqlInt64.Parse (x.Value);
+                       checked {
+                               return SqlInt64.Parse (x.Value);
+                       }
                }
 
                public static implicit operator SqlInt64 (long x)