* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseSingle.cs
1 //
2 // System.Data.SybaseTypes.SybaseSingle
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright 2002 Tim Coleman
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using Mono.Data.SybaseClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
35
36 namespace Mono.Data.SybaseTypes {
37         public struct SybaseSingle : INullable, IComparable
38         {
39                 #region Fields
40
41                 float value;
42
43                 private bool notNull;
44
45                 public static readonly SybaseSingle MaxValue = new SybaseSingle (3.40282346638528859e38);
46                 public static readonly SybaseSingle MinValue = new SybaseSingle (-3.40282346638528859e38);
47                 public static readonly SybaseSingle Null;
48                 public static readonly SybaseSingle Zero = new SybaseSingle (0);
49
50                 #endregion
51
52                 #region Constructors
53
54                 public SybaseSingle (double value) 
55                 {
56                         this.value = (float)value;
57                         notNull = true;
58                 }
59
60                 public SybaseSingle (float value) 
61                 {
62                         this.value = value;
63                         notNull = true;
64                 }
65
66                 #endregion
67
68                 #region Properties
69
70                 public bool IsNull { 
71                         get { return !notNull; }
72                 }
73
74                 public float Value { 
75                         get { 
76                                 if (this.IsNull) 
77                                         throw new SybaseNullValueException ();
78                                 else 
79                                         return value; 
80                         }
81                 }
82
83                 #endregion
84
85                 #region Methods
86
87                 public static SybaseSingle Add (SybaseSingle x, SybaseSingle y)
88                 {
89                         return (x + y);
90                 }
91
92                 public int CompareTo (object value)
93                 {
94                         if (value == null)
95                                 return 1;
96                         else if (!(value is SybaseSingle))
97                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseSingle"));
98                         else if (((SybaseSingle)value).IsNull)
99                                 return 1;
100                         else
101                                 return this.value.CompareTo (((SybaseSingle)value).Value);
102                 }
103
104                 public static SybaseSingle Divide (SybaseSingle x, SybaseSingle y)
105                 {
106                         return (x / y);
107                 }
108
109                 public override bool Equals (object value)
110                 {
111                         if (!(value is SybaseSingle))
112                                 return false;
113                         else
114                                 return (bool) (this == (SybaseSingle)value);
115                 }
116
117                 public static SybaseBoolean Equals (SybaseSingle x, SybaseSingle y)
118                 {
119                         return (x == y);
120                 }
121
122                 public override int GetHashCode ()
123                 {
124                         long LongValue = (long) value;
125                         return (int)(LongValue ^ (LongValue >> 32));
126                 }
127
128                 public static SybaseBoolean GreaterThan (SybaseSingle x, SybaseSingle y)
129                 {
130                         return (x > y);
131                 }
132
133                 public static SybaseBoolean GreaterThanOrEqual (SybaseSingle x, SybaseSingle y)
134                 {
135                         return (x >= y);
136                 }
137
138                 public static SybaseBoolean LessThan (SybaseSingle x, SybaseSingle y)
139                 {
140                         return (x < y);
141                 }
142
143                 public static SybaseBoolean LessThanOrEqual (SybaseSingle x, SybaseSingle y)
144                 {
145                         return (x <= y);
146                 }
147
148                 public static SybaseSingle Multiply (SybaseSingle x, SybaseSingle y)
149                 {
150                         return (x * y);
151                 }
152
153                 public static SybaseBoolean NotEquals (SybaseSingle x, SybaseSingle y)
154                 {
155                         return (x != y);
156                 }
157
158                 public static SybaseSingle Parse (string s)
159                 {
160                         return new SybaseSingle (Single.Parse (s));
161                 }
162
163                 public static SybaseSingle Subtract (SybaseSingle x, SybaseSingle y)
164                 {
165                         return (x - y);
166                 }
167
168                 public SybaseBoolean ToSybaseBoolean ()
169                 {
170                         return ((SybaseBoolean)this);
171                 }
172                 
173                 public SybaseByte ToSybaseByte ()
174                 {
175                         return ((SybaseByte)this);
176                 }
177
178                 public SybaseDecimal ToSybaseDecimal ()
179                 {
180                         return ((SybaseDecimal)this);
181                 }
182
183                 public SybaseDouble ToSybaseDouble ()
184                 {
185                         return ((SybaseDouble)this);
186                 }
187
188                 public SybaseInt16 ToSybaseInt16 ()
189                 {
190                         return ((SybaseInt16)this);
191                 }
192
193                 public SybaseInt32 ToSybaseInt32 ()
194                 {
195                         return ((SybaseInt32)this);
196                 }
197
198                 public SybaseInt64 ToSybaseInt64 ()
199                 {
200                         return ((SybaseInt64)this);
201                 }
202
203                 public SybaseMoney ToSybaseMoney ()
204                 {
205                         return ((SybaseMoney)this);
206                 }
207
208
209                 public SybaseString ToSybaseString ()
210                 {
211                         return ((SybaseString)this);
212                 }
213
214                 public override string ToString ()
215                 {
216                         return value.ToString ();
217                 }
218
219                 public static SybaseSingle operator + (SybaseSingle x, SybaseSingle y)
220                 {
221                         return new SybaseSingle (x.Value + y.Value);
222                 }
223
224                 public static SybaseSingle operator / (SybaseSingle x, SybaseSingle y)
225                 {
226                         return new SybaseSingle (x.Value / y.Value);
227                 }
228
229                 public static SybaseBoolean operator == (SybaseSingle x, SybaseSingle y)
230                 {
231                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
232                         return new SybaseBoolean (x.Value == y.Value);
233                 }
234
235                 public static SybaseBoolean operator > (SybaseSingle x, SybaseSingle y)
236                 {
237                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
238                         return new SybaseBoolean (x.Value > y.Value);
239                 }
240
241                 public static SybaseBoolean operator >= (SybaseSingle x, SybaseSingle y)
242                 {
243                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
244                         return new SybaseBoolean (x.Value >= y.Value);
245                 }
246
247                 public static SybaseBoolean operator != (SybaseSingle x, SybaseSingle y)
248                 {
249                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
250                         return new SybaseBoolean (!(x.Value == y.Value));
251                 }
252
253                 public static SybaseBoolean operator < (SybaseSingle x, SybaseSingle y)
254                 {
255                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
256                         return new SybaseBoolean (x.Value < y.Value);
257                 }
258
259                 public static SybaseBoolean operator <= (SybaseSingle x, SybaseSingle y)
260                 {
261                         if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
262                         return new SybaseBoolean (x.Value <= y.Value);
263                 }
264
265                 public static SybaseSingle operator * (SybaseSingle x, SybaseSingle y)
266                 {
267                         return new SybaseSingle (x.Value * y.Value);
268                 }
269
270                 public static SybaseSingle operator - (SybaseSingle x, SybaseSingle y)
271                 {
272                         return new SybaseSingle (x.Value - y.Value);
273                 }
274
275                 public static SybaseSingle operator - (SybaseSingle n)
276                 {
277                         return new SybaseSingle (-(n.Value));
278                 }
279
280                 public static explicit operator SybaseSingle (SybaseBoolean x)
281                 {
282                         return new SybaseSingle((float)x.ByteValue);
283                 }
284
285                 public static explicit operator SybaseSingle (SybaseDouble x)
286                 {
287                         return new SybaseSingle((float)x.Value);
288                 }
289
290                 public static explicit operator float (SybaseSingle x)
291                 {
292                         return x.Value;
293                 }
294
295                 public static explicit operator SybaseSingle (SybaseString x)
296                 {
297                         return SybaseSingle.Parse (x.Value);
298                 }
299
300                 public static implicit operator SybaseSingle (float x)
301                 {
302                         return new SybaseSingle (x);
303                 }
304
305                 public static implicit operator SybaseSingle (SybaseByte x)
306                 {
307                         if (x.IsNull) 
308                                 return Null;
309                         else
310                                 return new SybaseSingle((float)x.Value);
311                 }
312
313                 public static implicit operator SybaseSingle (SybaseDecimal x)
314                 {
315                         if (x.IsNull) 
316                                 return Null;
317                         else
318                                 return new SybaseSingle((float)x.Value);
319                 }
320
321                 public static implicit operator SybaseSingle (SybaseInt16 x)
322                 {
323                         if (x.IsNull) 
324                                 return Null;
325                         else
326                                 return new SybaseSingle((float)x.Value);
327                 }
328
329                 public static implicit operator SybaseSingle (SybaseInt32 x)
330                 {
331                         if (x.IsNull) 
332                                 return Null;
333                         else
334                                 return new SybaseSingle((float)x.Value);
335                 }
336
337                 public static implicit operator SybaseSingle (SybaseInt64 x)
338                 {
339                         if (x.IsNull) 
340                                 return Null;
341                         else
342                                 return new SybaseSingle((float)x.Value);
343                 }
344
345                 public static implicit operator SybaseSingle (SybaseMoney x)
346                 {
347                         if (x.IsNull) 
348                                 return Null;
349                         else
350                                 return new SybaseSingle((float)x.Value);
351                 }
352
353                 #endregion
354         }
355 }
356