[Task] Add an extra check in Task.WaitAny to make sure the index returned is valid
[mono.git] / mcs / class / Mono.C5 / C5 / Builtin.cs
index 3b6a4b017f45f53ba431b2cae656fd795ebf548b..ac115b093904db756b87c30ca1efb554bc95dadb 100644 (file)
-/*\r
- Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft\r
- Permission is hereby granted, free of charge, to any person obtaining a copy\r
- of this software and associated documentation files (the "Software"), to deal\r
- in the Software without restriction, including without limitation the rights\r
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
- copies of the Software, and to permit persons to whom the Software is\r
- furnished to do so, subject to the following conditions:\r
\r
- The above copyright notice and this permission notice shall be included in\r
- all copies or substantial portions of the Software.\r
\r
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- SOFTWARE.\r
-*/\r
-using System;\r
-using System.Diagnostics;\r
-using SCG = System.Collections.Generic;\r
-namespace C5\r
-{\r
-  #region int stuff\r
-  [Serializable]\r
-  class IntComparer : SCG.IComparer<int>\r
-  {\r
-    [Tested]\r
-    public int Compare(int a, int b) { return a > b ? 1 : a < b ? -1 : 0; }\r
-  }\r
-\r
-  /// <summary>\r
-  /// An equalityComparer for System.Int32 integers. \r
-  /// <para>This class is a singleton and the instance can be accessed\r
-  /// via the static <see cref="P:C5.IntEqualityComparer.Default"/> property</para>\r
-  /// </summary>\r
-  [Serializable]\r
-  public class IntEqualityComparer : SCG.IEqualityComparer<int>\r
-  {\r
-    static IntEqualityComparer cached;\r
-    IntEqualityComparer() { }\r
-    /// <summary>\r
-    /// \r
-    /// </summary>\r
-    /// <value></value>\r
-    [Tested]\r
-    public static IntEqualityComparer Default { get { return cached ?? (cached = new IntEqualityComparer()); } }\r
-    /// <summary>\r
-    /// Get the hash code of this integer, that is, itself\r
-    /// </summary>\r
-    /// <param name="item">The integer</param>\r
-    /// <returns>The same</returns>\r
-    [Tested]\r
-    public int GetHashCode(int item) { return item; }\r
-\r
-\r
-    /// <summary>\r
-    /// Determine whether two integers are equal\r
-    /// </summary>\r
-    /// <param name="int1">first integer</param>\r
-    /// <param name="int2">second integer</param>\r
-    /// <returns>True if equal</returns>\r
-    [Tested]\r
-    public bool Equals(int int1, int int2) { return int1 == int2; }\r
-  }\r
-\r
-  #endregion\r
-\r
-  #region double stuff\r
-  class DoubleComparer : SCG.IComparer<double>\r
-  {\r
-    public int Compare(double a, double b) { return a > b ? 1 : a < b ? -1 : 0; }\r
-  }\r
-\r
-  /// <summary>\r
-  /// An equalityComparer for double. \r
-  /// <para>This class is a singleton and the instance can be accessed\r
-  /// via the static <see cref="P:C5.DoubleEqualityComparer.Default"/> property</para>\r
-  /// </summary>\r
-  public class DoubleEqualityComparer : SCG.IEqualityComparer<double>\r
-  {\r
-    static DoubleEqualityComparer cached;\r
-    DoubleEqualityComparer() { }\r
-    /// <summary>\r
-    /// \r
-    /// </summary>\r
-    /// <value></value>\r
-    [Tested]\r
-    public static DoubleEqualityComparer Default { get { return cached ?? (cached = new DoubleEqualityComparer()); } }\r
-    /// <summary>\r
-    /// Get the hash code of this double,\r
-    /// </summary>\r
-    /// <param name="item">The double</param>\r
-    /// <returns>The same</returns>\r
-    [Tested]\r
-    public int GetHashCode(double item) { return item.GetHashCode(); }\r
-\r
-\r
-    /// <summary>\r
-    /// Check if two doubles are equal\r
-    /// </summary>\r
-    /// <param name="item1">first double</param>\r
-    /// <param name="item2">second double</param>\r
-    /// <returns>True if equal</returns>\r
-    [Tested]\r
-    public bool Equals(double item1, double item2) { return item1 == item2; }\r
-  }\r
-  #endregion\r
-\r
-  #region byte stuff\r
-  class ByteComparer : SCG.IComparer<byte>\r
-  {\r
-    public int Compare(byte a, byte b) { return a > b ? 1 : a < b ? -1 : 0; }\r
-  }\r
-\r
-  /// <summary>\r
-  /// An equalityComparer for byte\r
-  /// <para>This class is a singleton and the instance can be accessed\r
-  /// via the <see cref="P:C5.ByteEqualityComparer.Default"/> property</para>\r
-  /// </summary>\r
-  public class ByteEqualityComparer : SCG.IEqualityComparer<byte>\r
-  {\r
-    static ByteEqualityComparer cached = new ByteEqualityComparer();\r
-    ByteEqualityComparer() { }\r
-    /// <summary>\r
-    /// \r
-    /// </summary>\r
-    /// <value></value>\r
-    public static ByteEqualityComparer Default { get { return cached ?? (cached = new ByteEqualityComparer()); } }\r
-    /// <summary>\r
-    /// Get the hash code of this byte, i.e. itself\r
-    /// </summary>\r
-    /// <param name="item">The byte</param>\r
-    /// <returns>The same</returns>\r
-    public int GetHashCode(byte item) { return item; }\r
-\r
-    /// <summary>\r
-    /// Check if two bytes are equal\r
-    /// </summary>\r
-    /// <param name="item1">first byte</param>\r
-    /// <param name="item2">second byte</param>\r
-    /// <returns>True if equal</returns>\r
-    public bool Equals(byte item1, byte item2) { return item1 == item2; }\r
-  }\r
-  #endregion\r
-\r
-  #region char stuff\r
-  class CharComparer : SCG.IComparer<char>\r
-  {\r
-    public int Compare(char a, char b) { return a > b ? 1 : a < b ? -1 : 0; }\r
-  }\r
-\r
-  /// <summary>\r
-  /// An equalityComparer for char.\r
-  /// </summary>\r
-  public class CharEqualityComparer : SCG.IEqualityComparer<char>\r
-  {\r
-    static CharEqualityComparer cached = new CharEqualityComparer();\r
-    CharEqualityComparer() { }\r
-    /// <summary>\r
-    /// \r
-    /// </summary>\r
-    /// <value></value>\r
-    public static CharEqualityComparer Default { get { return cached ?? (cached = new CharEqualityComparer()); } }\r
-\r
-    /// <summary>\r
-    /// Get the hash code of this char\r
-    /// </summary>\r
-    /// <param name="item">The char</param>\r
-    /// <returns>The same</returns>\r
-    public int GetHashCode(char item) { return item.GetHashCode(); }\r
-\r
-\r
-    /// <summary>\r
-    /// Check if two chars are equal\r
-    /// </summary>\r
-    /// <param name="item1">first char</param>\r
-    /// <param name="item2">second char</param>\r
-    /// <returns>True if equal</returns>\r
-    public bool Equals(char item1, char item2) { return item1 == item2; }\r
-  }\r
-  #endregion\r
-\r
+/*
+ Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
+ 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.Diagnostics;
+using SCG = System.Collections.Generic;
+namespace C5
+{
+  #region char comparer and equality comparer
+  class CharComparer : SCG.IComparer<char>
+  {
+    public int Compare(char item1, char item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type char, also known as System.Char.
+  /// </summary>
+  public class CharEqualityComparer : SCG.IEqualityComparer<char>
+  {
+    static CharEqualityComparer cached = new CharEqualityComparer();
+    CharEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    public static CharEqualityComparer Default { get { return cached ?? (cached = new CharEqualityComparer()); } }
+
+    /// <summary>
+    /// Get the hash code of this char
+    /// </summary>
+    /// <param name="item">The char</param>
+    /// <returns>The same</returns>
+    public int GetHashCode(char item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Check if two chars are equal
+    /// </summary>
+    /// <param name="item1">first char</param>
+    /// <param name="item2">second char</param>
+    /// <returns>True if equal</returns>
+    public bool Equals(char item1, char item2) { return item1 == item2; }
+  }
+  #endregion
+  
+  #region sbyte comparer and equality comparer
+  [Serializable]
+  class SByteComparer : SCG.IComparer<sbyte>
+  {
+    [Tested]
+    public int Compare(sbyte item1, sbyte item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type sbyte, also known as System.SByte. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.SByteEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class SByteEqualityComparer : SCG.IEqualityComparer<sbyte>
+  {
+    static SByteEqualityComparer cached;
+    SByteEqualityComparer() { }
+
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static SByteEqualityComparer Default { get { return cached ?? (cached = new SByteEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this sbyte, that is, itself
+    /// </summary>
+    /// <param name="item">The sbyte</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(sbyte item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two sbytes are equal
+    /// </summary>
+    /// <param name="item1">first sbyte</param>
+    /// <param name="item2">second sbyte</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(sbyte item1, sbyte item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region byte comparer and equality comparer
+  class ByteComparer : SCG.IComparer<byte>
+  {
+    public int Compare(byte item1, byte item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type byte, also known as System.Byte.
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the <see cref="P:C5.ByteEqualityComparer.Default"/> property</para>
+  /// </summary>
+  public class ByteEqualityComparer : SCG.IEqualityComparer<byte>
+  {
+    static ByteEqualityComparer cached = new ByteEqualityComparer();
+    ByteEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    public static ByteEqualityComparer Default { get { return cached ?? (cached = new ByteEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this byte, i.e. itself
+    /// </summary>
+    /// <param name="item">The byte</param>
+    /// <returns>The same</returns>
+    public int GetHashCode(byte item) { return item.GetHashCode(); }
+
+    /// <summary>
+    /// Check if two bytes are equal
+    /// </summary>
+    /// <param name="item1">first byte</param>
+    /// <param name="item2">second byte</param>
+    /// <returns>True if equal</returns>
+    public bool Equals(byte item1, byte item2) { return item1 == item2; }
+  }
+  #endregion
+
+  #region short comparer and equality comparer
+  [Serializable]
+  class ShortComparer : SCG.IComparer<short>
+  {
+    [Tested]
+    public int Compare(short item1, short item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type short, also known as System.Int16. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.ShortEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class ShortEqualityComparer : SCG.IEqualityComparer<short>
+  {
+    static ShortEqualityComparer cached;
+    ShortEqualityComparer() { }
+
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static ShortEqualityComparer Default { get { return cached ?? (cached = new ShortEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this short, that is, itself
+    /// </summary>
+    /// <param name="item">The short</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(short item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two shorts are equal
+    /// </summary>
+    /// <param name="item1">first short</param>
+    /// <param name="item2">second short</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(short item1, short item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region ushort comparer and equality comparer
+  [Serializable]
+  class UShortComparer : SCG.IComparer<ushort>
+  {
+    [Tested]
+    public int Compare(ushort item1, ushort item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type ushort, also known as System.UInt16. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.UShortEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class UShortEqualityComparer : SCG.IEqualityComparer<ushort>
+  {
+    static UShortEqualityComparer cached;
+    UShortEqualityComparer() { }
+
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static UShortEqualityComparer Default { get { return cached ?? (cached = new UShortEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this ushort, that is, itself
+    /// </summary>
+    /// <param name="item">The ushort</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(ushort item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two ushorts are equal
+    /// </summary>
+    /// <param name="item1">first ushort</param>
+    /// <param name="item2">second ushort</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(ushort item1, ushort item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region int comparer and equality comparer
+  [Serializable]
+  class IntComparer : SCG.IComparer<int>
+  {
+    [Tested]
+    public int Compare(int item1, int item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type int, also known as System.Int32. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.IntEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class IntEqualityComparer : SCG.IEqualityComparer<int>
+  {
+    static IntEqualityComparer cached;
+    IntEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static IntEqualityComparer Default { get { return cached ?? (cached = new IntEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this integer, that is, itself
+    /// </summary>
+    /// <param name="item">The integer</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(int item) { return item; }
+
+
+    /// <summary>
+    /// Determine whether two integers are equal
+    /// </summary>
+    /// <param name="item1">first integer</param>
+    /// <param name="item2">second integer</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(int item1, int item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region uint comparer and equality comparer
+  [Serializable]
+  class UIntComparer : SCG.IComparer<uint>
+  {
+    [Tested]
+    public int Compare(uint item1, uint item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type uint, also known as System.UInt32. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.UIntEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class UIntEqualityComparer : SCG.IEqualityComparer<uint>
+  {
+    static UIntEqualityComparer cached;
+    UIntEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static UIntEqualityComparer Default { get { return cached ?? (cached = new UIntEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this unsigned integer
+    /// </summary>
+    /// <param name="item">The integer</param>
+    /// <returns>The same bit pattern as a signed integer</returns>
+    [Tested]
+    public int GetHashCode(uint item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two unsigned integers are equal
+    /// </summary>
+    /// <param name="item1">first unsigned integer</param>
+    /// <param name="item2">second unsigned integer</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(uint item1, uint item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region long comparer and equality comparer
+  [Serializable]
+  class LongComparer : SCG.IComparer<long>
+  {
+    [Tested]
+    public int Compare(long item1, long item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type long, also known as System.Int64. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.LongEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class LongEqualityComparer : SCG.IEqualityComparer<long>
+  {
+    static LongEqualityComparer cached;
+    LongEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static LongEqualityComparer Default { get { return cached ?? (cached = new LongEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this long integer
+    /// </summary>
+    /// <param name="item">The long integer</param>
+    /// <returns>The hash code</returns>
+    [Tested]
+    public int GetHashCode(long item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two long integers are equal
+    /// </summary>
+    /// <param name="item1">first long integer</param>
+    /// <param name="item2">second long integer</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(long item1, long item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region ulong comparer and equality comparer
+  [Serializable]
+  class ULongComparer : SCG.IComparer<ulong>
+  {
+    [Tested]
+    public int Compare(ulong item1, ulong item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type uint, also known as System.UInt64. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.ULongEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class ULongEqualityComparer : SCG.IEqualityComparer<ulong>
+  {
+    static ULongEqualityComparer cached;
+    ULongEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static ULongEqualityComparer Default { get { return cached ?? (cached = new ULongEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this unsigned long integer
+    /// </summary>
+    /// <param name="item">The unsigned long integer</param>
+    /// <returns>The hash code</returns>
+    [Tested]
+    public int GetHashCode(ulong item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two unsigned long integers are equal
+    /// </summary>
+    /// <param name="item1">first unsigned long integer</param>
+    /// <param name="item2">second unsigned long integer</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(ulong item1, ulong item2) { return item1 == item2; }
+  }
+
+  #endregion
+
+  #region float comparer and equality comparer
+  class FloatComparer : SCG.IComparer<float>
+  {
+    public int Compare(float item1, float item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type float, also known as System.Single. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.FloatEqualityComparer.Default"/> property</para>
+  /// </summary>
+  public class FloatEqualityComparer : SCG.IEqualityComparer<float>
+  {
+    static FloatEqualityComparer cached;
+    FloatEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static FloatEqualityComparer Default { get { return cached ?? (cached = new FloatEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this float
+    /// </summary>
+    /// <param name="item">The float</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(float item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Check if two floats are equal
+    /// </summary>
+    /// <param name="item1">first float</param>
+    /// <param name="item2">second float</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(float item1, float item2) { return item1 == item2; }
+  }
+  #endregion
+
+  #region double comparer and equality comparer
+  class DoubleComparer : SCG.IComparer<double>
+  {
+    public int Compare(double item1, double item2) { 
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0; 
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type double, also known as System.Double.
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.DoubleEqualityComparer.Default"/> property</para>
+  /// </summary>
+  public class DoubleEqualityComparer : SCG.IEqualityComparer<double>
+  {
+    static DoubleEqualityComparer cached;
+    DoubleEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static DoubleEqualityComparer Default { get { return cached ?? (cached = new DoubleEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this double
+    /// </summary>
+    /// <param name="item">The double</param>
+    /// <returns>The same</returns>
+    [Tested]
+    public int GetHashCode(double item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Check if two doubles are equal
+    /// </summary>
+    /// <param name="item1">first double</param>
+    /// <param name="item2">second double</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(double item1, double item2) { return item1 == item2; }
+  }
+  #endregion
+
+  #region decimal comparer and equality comparer
+  [Serializable]
+  class DecimalComparer : SCG.IComparer<decimal>
+  {
+    [Tested]
+    public int Compare(decimal item1, decimal item2)
+    {
+      return item1 > item2 ? 1 : item1 < item2 ? -1 : 0;
+    }
+  }
+
+  /// <summary>
+  /// An equality comparer for type decimal, also known as System.Decimal. 
+  /// <para>This class is a singleton and the instance can be accessed
+  /// via the static <see cref="P:C5.DecimalEqualityComparer.Default"/> property</para>
+  /// </summary>
+  [Serializable]
+  public class DecimalEqualityComparer : SCG.IEqualityComparer<decimal>
+  {
+    static DecimalEqualityComparer cached;
+    DecimalEqualityComparer() { }
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <value></value>
+    [Tested]
+    public static DecimalEqualityComparer Default { get { return cached ?? (cached = new DecimalEqualityComparer()); } }
+    /// <summary>
+    /// Get the hash code of this decimal.
+    /// </summary>
+    /// <param name="item">The decimal</param>
+    /// <returns>The hash code</returns>
+    [Tested]
+    public int GetHashCode(decimal item) { return item.GetHashCode(); }
+
+
+    /// <summary>
+    /// Determine whether two decimals are equal
+    /// </summary>
+    /// <param name="item1">first decimal</param>
+    /// <param name="item2">second decimal</param>
+    /// <returns>True if equal</returns>
+    [Tested]
+    public bool Equals(decimal item1, decimal item2) { return item1 == item2; }
+  }
+
+  #endregion
 }
\ No newline at end of file