2 // System.Data.SybaseTypes.SybaseSingle
5 // Tim Coleman <tim@timcoleman.com>
7 // (C) Copyright 2002 Tim Coleman
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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
;
33 using System
.Data
.SqlTypes
;
34 using System
.Globalization
;
36 namespace Mono
.Data
.SybaseTypes
{
37 public struct SybaseSingle
: INullable
, IComparable
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);
54 public SybaseSingle (double value)
56 this.value = (float)value;
60 public SybaseSingle (float value)
71 get { return !notNull; }
77 throw new SybaseNullValueException ();
87 public static SybaseSingle
Add (SybaseSingle x
, SybaseSingle y
)
92 public int CompareTo (object value)
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
)
101 return this.value.CompareTo (((SybaseSingle
)value).Value
);
104 public static SybaseSingle
Divide (SybaseSingle x
, SybaseSingle y
)
109 public override bool Equals (object value)
111 if (!(value is SybaseSingle
))
114 return (bool) (this == (SybaseSingle
)value);
117 public static SybaseBoolean
Equals (SybaseSingle x
, SybaseSingle 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
)
133 public static SybaseBoolean
GreaterThanOrEqual (SybaseSingle x
, SybaseSingle y
)
138 public static SybaseBoolean
LessThan (SybaseSingle x
, SybaseSingle y
)
143 public static SybaseBoolean
LessThanOrEqual (SybaseSingle x
, SybaseSingle y
)
148 public static SybaseSingle
Multiply (SybaseSingle x
, SybaseSingle y
)
153 public static SybaseBoolean
NotEquals (SybaseSingle x
, SybaseSingle y
)
158 public static SybaseSingle
Parse (string s
)
160 return new SybaseSingle (Single
.Parse (s
));
163 public static SybaseSingle
Subtract (SybaseSingle x
, SybaseSingle 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
)
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
)
310 return new SybaseSingle((float)x
.Value
);
313 public static implicit operator SybaseSingle (SybaseDecimal x
)
318 return new SybaseSingle((float)x
.Value
);
321 public static implicit operator SybaseSingle (SybaseInt16 x
)
326 return new SybaseSingle((float)x
.Value
);
329 public static implicit operator SybaseSingle (SybaseInt32 x
)
334 return new SybaseSingle((float)x
.Value
);
337 public static implicit operator SybaseSingle (SybaseInt64 x
)
342 return new SybaseSingle((float)x
.Value
);
345 public static implicit operator SybaseSingle (SybaseMoney x
)
350 return new SybaseSingle((float)x
.Value
);