2002-01-05 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / System / Single.cs
1 //
2 // System.Single.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.Globalization;
11
12 namespace System {
13         
14         public struct Single : IComparable, IFormattable { //, IConvertible {
15                 public const float Epsilon = 1.4e-45f;
16                 public const float MaxValue =  3.40282346638528859e38f;
17                 public const float MinValue = -3.40282346638528859e38f;
18                 public const float NaN = 0.0f / 0.0f;
19                 public const float PositiveInfinity =  1.0f / 0.0f;
20                 public const float NegativeInfinity = -1.0f / 0.0f;
21                         
22                 // VES needs to know about value.  public is workaround
23                 // so source will compile
24                 public float value;
25                         
26                 public int CompareTo (object v)
27                 {
28                         if (v == null)
29                                 return 1;
30
31                         if (!(v is System.Single))
32                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Single"));
33
34                         return (int) (value - ((float) v));
35                 }
36
37                 public override bool Equals (object o)
38                 {
39                         if (!(o is System.Single))
40                                 return false;
41
42                         return ((float) o) == value;
43                 }
44
45                 public override int GetHashCode ()
46                 {
47                         return (int) value;
48                 }
49
50                 public static bool IsInfinity (float f)
51                 {
52                         return (f == PositiveInfinity || f == NegativeInfinity);
53                 }
54
55                 public static bool IsNaN (float f)
56                 {
57                         return (f != f);
58                 }
59
60                 public static bool IsNegativeInfinity (float f)
61                 {
62                         return (f < 0.0f && (f == NegativeInfinity || f == PositiveInfinity));
63                 }
64
65                 public static bool IsPositiveInfinity (float f)
66                 {
67                         return (f > 0.0f && (f == NegativeInfinity || f == PositiveInfinity));
68                 }
69
70                 public static float Parse (string s)
71                 {
72                         return Parse (s, (NumberStyles.Float | NumberStyles.AllowThousands), null);
73                 }
74
75                 public static float Parse (string s, IFormatProvider fp)
76                 {
77                         return Parse (s, (NumberStyles.Float | NumberStyles.AllowThousands), fp);
78                 }
79                 
80                 public static float Parse (string s, NumberStyles style)
81                 {
82                         return Parse (s, style, null);
83                 }
84
85                 [MonoTODO]
86                 public static float Parse (string s, NumberStyles style, IFormatProvider fp)
87                 {
88                         // TODO: Implement me
89                         throw new NotImplementedException ();
90                 }
91
92                 public override string ToString ()
93                 {
94                         return ToString(null, null);
95                 }
96
97                 public string ToString (IFormatProvider fp)
98                 {
99                         return ToString(null, fp);
100                 }
101
102                 public string ToString (string format)
103                 {
104                         return ToString(format, null);
105                 }
106
107                 [MonoTODO]
108                 public string ToString (string format, IFormatProvider fp)
109                 {
110                         // TODO: Implement me.
111                         throw new NotImplementedException ();
112                 }
113
114                 // ============= IConvertible Methods ============ //
115
116                 public TypeCode GetTypeCode ()
117                 {
118                         return TypeCode.Single;
119                 }
120         }
121 }