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 {
16 public const long MaxValue = 0x7fffffffffffffff;
17 public const long MinValue = -9223372036854775808;
21 public int CompareTo (object v)
26 if (!(v is System.Int64))
27 throw new ArgumentException (Locale.GetText ("Value is not a System.Int64"));
29 if (value == (long) v)
38 public override bool Equals (object o)
40 if (!(o is System.Int64))
43 return ((long) o) == value;
46 public override int GetHashCode ()
48 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
51 public static long Parse (string s)
57 bool digits_seen = false;
60 throw new ArgumentNullException (Locale.GetText ("s is null"));
65 for (i = 0; i < len; i++){
67 if (!Char.IsWhiteSpace (c))
72 throw new FormatException ();
85 if (c >= '0' && c <= '9'){
86 val = checked (val * 10 + (c - '0'));
89 if (Char.IsWhiteSpace (c)){
90 for (i++; i < len; i++){
91 if (!Char.IsWhiteSpace (s [i]))
92 throw new FormatException ();
96 throw new FormatException ();
100 throw new FormatException ();
108 public static long Parse (string s, IFormatProvider fp)
110 return Parse (s, NumberStyles.Integer, fp);
113 public static long Parse (string s, NumberStyles style)
115 return Parse (s, style, null);
119 public static long Parse (string s, NumberStyles style, IFormatProvider fp)
121 // TODO: Implement me
122 // throw new NotImplementedException ();
123 // good enough for now
127 public override string ToString ()
129 return ToString (null, null);
132 public string ToString (IFormatProvider fp)
134 return ToString (null, fp);
137 public string ToString (string format)
139 return ToString (format, null);
142 public string ToString (string format, IFormatProvider fp)
144 NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
146 if ( format == null )
149 return IntegerFormatter.NumberToString (format, nfi, value);
152 // =========== IConvertible Methods =========== //
154 public TypeCode GetTypeCode ()
156 return TypeCode.Int64;