2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System / Single.cs
index ac69109b1dbc3d257210dcc5f9a29fa63c542902..bd6992946b4c42f3cb5895b6fb9b3514c066d624 100644 (file)
@@ -36,6 +36,9 @@ namespace System
 {
        [Serializable]
        public struct Single : IComparable, IFormattable, IConvertible
+#if NET_2_0
+               , IComparable <float>
+#endif
        {
                public const float Epsilon = 1.4e-45f;
                public const float MaxValue =  3.40282346638528859e38f;
@@ -94,9 +97,48 @@ namespace System
                        return ((float) o) == m_value;
                }
 
-               public override int GetHashCode ()
+#if NET_2_0
+               public int CompareTo (float value)
                {
-                       return (int) m_value;
+                       if (IsPositiveInfinity (m_value) && IsPositiveInfinity (value))
+                               return 0;
+
+                       if (IsNegativeInfinity (m_value) && IsNegativeInfinity (value))
+                               return 0;
+
+                       if (IsNaN (value))
+                               if (IsNaN (m_value))
+                                       return 0;
+                               else
+                                       return 1;
+
+                       if (IsNaN (m_value))
+                               if (IsNaN (value))
+                                       return 0;
+                               else
+                                       return -1;
+
+                       if (this.m_value == value)
+                               return 0;
+                       else if (this.m_value > value)
+                               return 1;
+                       else
+                               return -1;
+               }
+
+               public bool Equals (float value)
+               {
+                       if (IsNaN (value))
+                               return IsNaN (m_value);
+
+                       return value == m_value;
+               }
+#endif
+
+               public unsafe override int GetHashCode ()
+               {
+                       float f = m_value;
+                       return *((int*)&f);
                }
 
                public static bool IsInfinity (float f)