5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
15 public struct UInt64 : IComparable, IFormattable { //, IConvertible {
16 private static Type Type = typeof (ulong);
18 public const ulong MaxValue = 0xffffffffffffffff;
19 public const ulong MinValue = 0;
23 public int CompareTo (object v)
28 if (!(v is System.UInt64))
29 throw new ArgumentException (Locale.GetText ("Value is not a System.UInt64"));
31 if (value == (ulong) v)
34 if (value < (ulong) v)
40 public override bool Equals (object o)
42 if (!(o is System.UInt64))
45 return ((ulong) o) == value;
48 public override int GetHashCode ()
50 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
53 public static ulong Parse (string s)
58 bool digits_seen = false;
61 throw new ArgumentNullException (Locale.GetText ("s is null"));
66 for (i = 0; i < len; i++){
68 if (!Char.IsWhiteSpace (c))
73 throw new FormatException ();
81 if (c >= '0' && c <= '9'){
82 uint d = (uint) (c - '0');
84 val = checked (val * 10 + d);
87 if (Char.IsWhiteSpace (c)){
88 for (i++; i < len; i++){
89 if (!Char.IsWhiteSpace (s [i]))
90 throw new FormatException ();
94 throw new FormatException ();
98 throw new FormatException ();
104 public static ulong Parse (string s, IFormatProvider fp)
106 return Parse (s, NumberStyles.Integer, fp);
109 public static ulong Parse (string s, NumberStyles style)
111 return Parse (s, style, null);
114 public static ulong Parse (string s, NumberStyles style, IFormatProvider fp)
118 for (j = 0; j < s.Length; ++j) {
119 if (s [j] >= '0' && s [j] <= '9')
120 val = val * 10 + s [j] - '0';
127 public override string ToString ()
129 return ToString ("G", null);
132 public string ToString (IFormatProvider fp)
134 return ToString ("G", fp);
137 public string ToString (string format)
139 return ToString (format, null);
142 public string ToString (string format, IFormatProvider fp)
145 NumberFormatInfo nfi;
147 fmt = (format == null) ? "G" : format;
150 nfi = NumberFormatInfo.CurrentInfo;
152 nfi = (NumberFormatInfo) fp.GetFormat (Type);
155 nfi = NumberFormatInfo.CurrentInfo;
158 return IntegerFormatter.NumberToString (fmt, nfi, value);
161 // =========== IConvertible Methods =========== //
163 public TypeCode GetTypeCode ()
165 return TypeCode.UInt64;