2 // System.Data.SqlTypes.SqlSingle
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@koti.soon.fi>
8 // (C) Copyright 2002 Tim Coleman
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Xml.Schema;
37 using System.Globalization;
38 using System.Xml.Serialization;
40 namespace System.Data.SqlTypes
43 [SerializableAttribute]
44 [XmlSchemaProvider ("GetSchema")]
46 public struct SqlSingle : INullable, IComparable
57 public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859E+38f);
58 public static readonly SqlSingle MinValue = new SqlSingle (-3.40282346638528859E+38f);
59 public static readonly SqlSingle Null;
60 public static readonly SqlSingle Zero = new SqlSingle (0);
66 public SqlSingle (double value)
68 this.value = (float)value;
72 public SqlSingle (float value)
83 get { return !notNull; }
89 throw new SqlNullValueException ();
99 public static SqlSingle Add (SqlSingle x, SqlSingle y)
104 public int CompareTo (object value)
108 else if (!(value is SqlSingle))
109 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlSingle"));
111 return CompareSqlSingle ((SqlSingle) value);
115 public int CompareTo (SqlSingle value)
117 return CompareSqlSingle (value);
121 private int CompareSqlSingle (SqlSingle value)
126 return this.value.CompareTo (value.Value);
129 public static SqlSingle Divide (SqlSingle x, SqlSingle y)
134 public override bool Equals (object value)
136 if (!(value is SqlSingle))
138 else if (this.IsNull && ((SqlSingle)value).IsNull)
140 else if (((SqlSingle)value).IsNull)
143 return (bool) (this == (SqlSingle)value);
146 public static SqlBoolean Equals (SqlSingle x, SqlSingle y)
151 public override int GetHashCode ()
153 long LongValue = (long) value;
154 return (int)(LongValue ^ (LongValue >> 32));
157 public static SqlBoolean GreaterThan (SqlSingle x, SqlSingle y)
162 public static SqlBoolean GreaterThanOrEqual (SqlSingle x, SqlSingle y)
167 public static SqlBoolean LessThan (SqlSingle x, SqlSingle y)
172 public static SqlBoolean LessThanOrEqual (SqlSingle x, SqlSingle y)
177 public static SqlSingle Multiply (SqlSingle x, SqlSingle y)
182 public static SqlBoolean NotEquals (SqlSingle x, SqlSingle y)
187 public static SqlSingle Parse (string s)
189 return new SqlSingle (Single.Parse (s));
192 public static SqlSingle Subtract (SqlSingle x, SqlSingle y)
197 public SqlBoolean ToSqlBoolean ()
199 return ((SqlBoolean)this);
202 public SqlByte ToSqlByte ()
204 return ((SqlByte)this);
207 public SqlDecimal ToSqlDecimal ()
209 return ((SqlDecimal)this);
212 public SqlDouble ToSqlDouble ()
214 return ((SqlDouble)this);
217 public SqlInt16 ToSqlInt16 ()
219 return ((SqlInt16)this);
222 public SqlInt32 ToSqlInt32 ()
224 return ((SqlInt32)this);
227 public SqlInt64 ToSqlInt64 ()
229 return ((SqlInt64)this);
232 public SqlMoney ToSqlMoney ()
234 return ((SqlMoney)this);
238 public SqlString ToSqlString ()
240 return ((SqlString)this);
243 public override string ToString ()
247 return value.ToString ();
250 public static SqlSingle operator + (SqlSingle x, SqlSingle y)
252 float f = (float)(x.Value + y.Value);
254 if (Single.IsInfinity (f))
255 throw new OverflowException ();
257 return new SqlSingle (f);
260 public static SqlSingle operator / (SqlSingle x, SqlSingle y)
262 float f = (float)(x.Value / y.Value);
264 if (Single.IsInfinity (f)) {
267 throw new DivideByZeroException ();
270 return new SqlSingle (x.Value / y.Value);
273 public static SqlBoolean operator == (SqlSingle x, SqlSingle y)
275 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
276 return new SqlBoolean (x.Value == y.Value);
279 public static SqlBoolean operator > (SqlSingle x, SqlSingle y)
281 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
282 return new SqlBoolean (x.Value > y.Value);
285 public static SqlBoolean operator >= (SqlSingle x, SqlSingle y)
287 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
288 return new SqlBoolean (x.Value >= y.Value);
291 public static SqlBoolean operator != (SqlSingle x, SqlSingle y)
293 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
294 return new SqlBoolean (!(x.Value == y.Value));
297 public static SqlBoolean operator < (SqlSingle x, SqlSingle y)
299 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
300 return new SqlBoolean (x.Value < y.Value);
303 public static SqlBoolean operator <= (SqlSingle x, SqlSingle y)
305 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
306 return new SqlBoolean (x.Value <= y.Value);
309 public static SqlSingle operator * (SqlSingle x, SqlSingle y)
311 float f = (float)(x.Value * y.Value);
313 if (Single.IsInfinity (f))
314 throw new OverflowException ();
316 return new SqlSingle (f);
319 public static SqlSingle operator - (SqlSingle x, SqlSingle y)
321 float f = (float)(x.Value - y.Value);
323 if (Single.IsInfinity (f))
324 throw new OverflowException ();
326 return new SqlSingle (f);
329 public static SqlSingle operator - (SqlSingle n)
331 return new SqlSingle (-(n.Value));
334 public static explicit operator SqlSingle (SqlBoolean x)
340 return new SqlSingle((float)x.ByteValue);
344 public static explicit operator SqlSingle (SqlDouble x)
349 float f = (float)x.Value;
351 if (Single.IsInfinity (f))
352 throw new OverflowException ();
354 return new SqlSingle(f);
357 public static explicit operator float (SqlSingle x)
362 public static explicit operator SqlSingle (SqlString x)
368 return SqlSingle.Parse (x.Value);
372 public static implicit operator SqlSingle (float x)
374 return new SqlSingle (x);
377 public static implicit operator SqlSingle (SqlByte x)
382 return new SqlSingle((float)x.Value);
385 public static implicit operator SqlSingle (SqlDecimal x)
390 return new SqlSingle((float)x.Value);
393 public static implicit operator SqlSingle (SqlInt16 x)
398 return new SqlSingle((float)x.Value);
401 public static implicit operator SqlSingle (SqlInt32 x)
406 return new SqlSingle((float)x.Value);
409 public static implicit operator SqlSingle (SqlInt64 x)
414 return new SqlSingle((float)x.Value);
417 public static implicit operator SqlSingle (SqlMoney x)
422 return new SqlSingle((float)x.Value);
427 XmlSchema IXmlSerializable.GetSchema ()
429 throw new NotImplementedException ();
433 void IXmlSerializable.ReadXml (XmlReader reader)
435 throw new NotImplementedException ();
439 void IXmlSerializable.WriteXml (XmlWriter writer)
441 throw new NotImplementedException ();