* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlInt64.cs
index bdd808582560c33df69718ac8eab107b8cc7f272..c9a22a2632761315544601b2914fd7f4d88db4fe 100644 (file)
@@ -8,6 +8,29 @@
 // (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;
 
@@ -79,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)
@@ -137,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);
@@ -355,12 +397,13 @@ namespace System.Data.SqlTypes
 
                public static explicit operator SqlInt64 (SqlDouble x)
                {
-                       //checked {
-                               if (x.IsNull) 
-                                       return SqlInt64.Null;
-                               else
+                       if (x.IsNull) 
+                               return SqlInt64.Null;
+                       else {
+                               checked {
                                        return new SqlInt64 ((long)x.Value);
-                               //}
+                               }
+                       }
                }
 
                public static explicit operator long (SqlInt64 x)
@@ -374,18 +417,19 @@ namespace System.Data.SqlTypes
                                if (x.IsNull) 
                                        return SqlInt64.Null;
                                else
-                                       return new SqlInt64 ((long)x.Value);
+                                       return new SqlInt64 ((long) Math.Round (x.Value));
                        }
                }
 
                public static explicit operator SqlInt64 (SqlSingle x)
                {
-                       //checked {
-                               if (x.IsNull) 
-                                       return SqlInt64.Null;
-                               else
+                       if (x.IsNull) 
+                               return SqlInt64.Null;
+                       else {
+                               checked {
                                        return new SqlInt64 ((long)x.Value);
-                               //}
+                               }
+                       }
                }
 
                public static explicit operator SqlInt64 (SqlString x)