5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
14 public struct Int64 : IComparable, IFormattable { //, IConvertible {
15 private static Type Type = typeof (long);
17 public const long MaxValue = 0x7fffffffffffffff;
18 public const long MinValue = -9223372036854775808;
22 public int CompareTo (object v)
27 if (!(v is System.Int64))
28 throw new ArgumentException (Locale.GetText ("Value is not a System.Int64"));
30 if (value == (long) v)
39 public override bool Equals (object o)
41 if (!(o is System.Int64))
44 return ((long) o) == value;
47 public override int GetHashCode ()
49 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
52 public static long 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 ();
86 if (c >= '0' && c <= '9'){
87 val = checked (val * 10 + (c - '0'));
90 if (Char.IsWhiteSpace (c)){
91 for (i++; i < len; i++){
92 if (!Char.IsWhiteSpace (s [i]))
93 throw new FormatException ();
97 throw new FormatException ();
101 throw new FormatException ();
109 public static long Parse (string s, IFormatProvider fp)
111 return Parse (s, NumberStyles.Integer, fp);
114 public static long Parse (string s, NumberStyles style)
116 return Parse (s, style, null);
120 public static long Parse (string s, NumberStyles style, IFormatProvider fp)
122 // TODO: Implement me
123 throw new NotImplementedException ();
126 public override string ToString ()
128 return ToString ("G", null);
131 public string ToString (IFormatProvider fp)
133 return ToString ("G", fp);
136 public string ToString (string format)
138 return ToString (format, null);
141 public string ToString (string format, IFormatProvider fp)
144 NumberFormatInfo nfi;
146 fmt = (format == null) ? "G" : format;
149 nfi = NumberFormatInfo.CurrentInfo;
151 nfi = (NumberFormatInfo) fp.GetFormat (Type);
154 nfi = NumberFormatInfo.CurrentInfo;
157 return IntegerFormatter.NumberToString (fmt, nfi, value);
160 // =========== IConvertible Methods =========== //
162 public TypeCode GetTypeCode ()
164 return TypeCode.Int64;