**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseSingle.cs
blob0573e32286bf903e2508b1868c52995448bbee31
1 //
2 // System.Data.SybaseTypes.SybaseSingle
3 //
4 // Author:
5 // Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright 2002 Tim Coleman
8 //
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.
31 using Mono.Data.SybaseClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
36 namespace Mono.Data.SybaseTypes {
37 public struct SybaseSingle : INullable, IComparable
39 #region Fields
41 float value;
43 private bool notNull;
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);
50 #endregion
52 #region Constructors
54 public SybaseSingle (double value)
56 this.value = (float)value;
57 notNull = true;
60 public SybaseSingle (float value)
62 this.value = value;
63 notNull = true;
66 #endregion
68 #region Properties
70 public bool IsNull {
71 get { return !notNull; }
74 public float Value {
75 get {
76 if (this.IsNull)
77 throw new SybaseNullValueException ();
78 else
79 return value;
83 #endregion
85 #region Methods
87 public static SybaseSingle Add (SybaseSingle x, SybaseSingle y)
89 return (x + y);
92 public int CompareTo (object value)
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);
104 public static SybaseSingle Divide (SybaseSingle x, SybaseSingle y)
106 return (x / y);
109 public override bool Equals (object value)
111 if (!(value is SybaseSingle))
112 return false;
113 else
114 return (bool) (this == (SybaseSingle)value);
117 public static SybaseBoolean Equals (SybaseSingle x, SybaseSingle y)
119 return (x == y);
122 public override int GetHashCode ()
124 long LongValue = (long) value;
125 return (int)(LongValue ^ (LongValue >> 32));
128 public static SybaseBoolean GreaterThan (SybaseSingle x, SybaseSingle y)
130 return (x > y);
133 public static SybaseBoolean GreaterThanOrEqual (SybaseSingle x, SybaseSingle y)
135 return (x >= y);
138 public static SybaseBoolean LessThan (SybaseSingle x, SybaseSingle y)
140 return (x < y);
143 public static SybaseBoolean LessThanOrEqual (SybaseSingle x, SybaseSingle y)
145 return (x <= y);
148 public static SybaseSingle Multiply (SybaseSingle x, SybaseSingle y)
150 return (x * y);
153 public static SybaseBoolean NotEquals (SybaseSingle x, SybaseSingle y)
155 return (x != y);
158 public static SybaseSingle Parse (string s)
160 return new SybaseSingle (Single.Parse (s));
163 public static SybaseSingle Subtract (SybaseSingle x, SybaseSingle y)
165 return (x - y);
168 public SybaseBoolean ToSybaseBoolean ()
170 return ((SybaseBoolean)this);
173 public SybaseByte ToSybaseByte ()
175 return ((SybaseByte)this);
178 public SybaseDecimal ToSybaseDecimal ()
180 return ((SybaseDecimal)this);
183 public SybaseDouble ToSybaseDouble ()
185 return ((SybaseDouble)this);
188 public SybaseInt16 ToSybaseInt16 ()
190 return ((SybaseInt16)this);
193 public SybaseInt32 ToSybaseInt32 ()
195 return ((SybaseInt32)this);
198 public SybaseInt64 ToSybaseInt64 ()
200 return ((SybaseInt64)this);
203 public SybaseMoney ToSybaseMoney ()
205 return ((SybaseMoney)this);
209 public SybaseString ToSybaseString ()
211 return ((SybaseString)this);
214 public override string ToString ()
216 return value.ToString ();
219 public static SybaseSingle operator + (SybaseSingle x, SybaseSingle y)
221 return new SybaseSingle (x.Value + y.Value);
224 public static SybaseSingle operator / (SybaseSingle x, SybaseSingle y)
226 return new SybaseSingle (x.Value / y.Value);
229 public static SybaseBoolean operator == (SybaseSingle x, SybaseSingle y)
231 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
232 return new SybaseBoolean (x.Value == y.Value);
235 public static SybaseBoolean operator > (SybaseSingle x, SybaseSingle y)
237 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
238 return new SybaseBoolean (x.Value > y.Value);
241 public static SybaseBoolean operator >= (SybaseSingle x, SybaseSingle y)
243 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
244 return new SybaseBoolean (x.Value >= y.Value);
247 public static SybaseBoolean operator != (SybaseSingle x, SybaseSingle y)
249 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
250 return new SybaseBoolean (!(x.Value == y.Value));
253 public static SybaseBoolean operator < (SybaseSingle x, SybaseSingle y)
255 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
256 return new SybaseBoolean (x.Value < y.Value);
259 public static SybaseBoolean operator <= (SybaseSingle x, SybaseSingle y)
261 if (x.IsNull || y .IsNull) return SybaseBoolean.Null;
262 return new SybaseBoolean (x.Value <= y.Value);
265 public static SybaseSingle operator * (SybaseSingle x, SybaseSingle y)
267 return new SybaseSingle (x.Value * y.Value);
270 public static SybaseSingle operator - (SybaseSingle x, SybaseSingle y)
272 return new SybaseSingle (x.Value - y.Value);
275 public static SybaseSingle operator - (SybaseSingle n)
277 return new SybaseSingle (-(n.Value));
280 public static explicit operator SybaseSingle (SybaseBoolean x)
282 return new SybaseSingle((float)x.ByteValue);
285 public static explicit operator SybaseSingle (SybaseDouble x)
287 return new SybaseSingle((float)x.Value);
290 public static explicit operator float (SybaseSingle x)
292 return x.Value;
295 public static explicit operator SybaseSingle (SybaseString x)
297 return SybaseSingle.Parse (x.Value);
300 public static implicit operator SybaseSingle (float x)
302 return new SybaseSingle (x);
305 public static implicit operator SybaseSingle (SybaseByte x)
307 if (x.IsNull)
308 return Null;
309 else
310 return new SybaseSingle((float)x.Value);
313 public static implicit operator SybaseSingle (SybaseDecimal x)
315 if (x.IsNull)
316 return Null;
317 else
318 return new SybaseSingle((float)x.Value);
321 public static implicit operator SybaseSingle (SybaseInt16 x)
323 if (x.IsNull)
324 return Null;
325 else
326 return new SybaseSingle((float)x.Value);
329 public static implicit operator SybaseSingle (SybaseInt32 x)
331 if (x.IsNull)
332 return Null;
333 else
334 return new SybaseSingle((float)x.Value);
337 public static implicit operator SybaseSingle (SybaseInt64 x)
339 if (x.IsNull)
340 return Null;
341 else
342 return new SybaseSingle((float)x.Value);
345 public static implicit operator SybaseSingle (SybaseMoney x)
347 if (x.IsNull)
348 return Null;
349 else
350 return new SybaseSingle((float)x.Value);
353 #endregion