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 ("GetXsdType")]
46 public struct SqlSingle : INullable, IComparable
56 public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859E+38f);
57 public static readonly SqlSingle MinValue = new SqlSingle (-3.40282346638528859E+38f);
58 public static readonly SqlSingle Null;
59 public static readonly SqlSingle Zero = new SqlSingle (0);
65 public SqlSingle (double value)
67 this.value = (float)value;
71 public SqlSingle (float value)
82 get { return !notNull; }
88 throw new SqlNullValueException ();
98 public static SqlSingle Add (SqlSingle x, SqlSingle y)
103 public int CompareTo (object value)
107 else if (!(value is SqlSingle))
108 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlSingle"));
110 return CompareSqlSingle ((SqlSingle) value);
114 public int CompareTo (SqlSingle value)
116 return CompareSqlSingle (value);
120 private int CompareSqlSingle (SqlSingle value)
125 return this.value.CompareTo (value.Value);
128 public static SqlSingle Divide (SqlSingle x, SqlSingle y)
133 public override bool Equals (object value)
135 if (!(value is SqlSingle))
137 else if (this.IsNull)
138 return ((SqlSingle)value).IsNull;
139 else if (((SqlSingle)value).IsNull)
142 return (bool) (this == (SqlSingle)value);
145 public static SqlBoolean Equals (SqlSingle x, SqlSingle y)
150 public override int GetHashCode ()
152 long LongValue = (long) value;
153 return (int) (LongValue ^ (LongValue >> 32));
156 public static SqlBoolean GreaterThan (SqlSingle x, SqlSingle y)
161 public static SqlBoolean GreaterThanOrEqual (SqlSingle x, SqlSingle y)
166 public static SqlBoolean LessThan (SqlSingle x, SqlSingle y)
171 public static SqlBoolean LessThanOrEqual (SqlSingle x, SqlSingle y)
176 public static SqlSingle Multiply (SqlSingle x, SqlSingle y)
181 public static SqlBoolean NotEquals (SqlSingle x, SqlSingle y)
186 public static SqlSingle Parse (string s)
188 return new SqlSingle (Single.Parse (s));
191 public static SqlSingle Subtract (SqlSingle x, SqlSingle y)
196 public SqlBoolean ToSqlBoolean ()
198 return ((SqlBoolean) this);
201 public SqlByte ToSqlByte ()
203 return ((SqlByte) this);
206 public SqlDecimal ToSqlDecimal ()
208 return ((SqlDecimal) this);
211 public SqlDouble ToSqlDouble ()
213 return ((SqlDouble) this);
216 public SqlInt16 ToSqlInt16 ()
218 return ((SqlInt16) this);
221 public SqlInt32 ToSqlInt32 ()
223 return ((SqlInt32) this);
226 public SqlInt64 ToSqlInt64 ()
228 return ((SqlInt64) this);
231 public SqlMoney ToSqlMoney ()
233 return ((SqlMoney) this);
236 public SqlString ToSqlString ()
238 return ((SqlString) this);
241 public override string ToString ()
245 return value.ToString ();
248 public static SqlSingle operator + (SqlSingle x, SqlSingle y)
250 float f = (float) (x.Value + y.Value);
252 if (Single.IsInfinity (f))
253 throw new OverflowException ();
255 return new SqlSingle (f);
258 public static SqlSingle operator / (SqlSingle x, SqlSingle y)
260 float f = (float) (x.Value / y.Value);
262 if (Single.IsInfinity (f)) {
264 throw new DivideByZeroException ();
267 return new SqlSingle (x.Value / y.Value);
270 public static SqlBoolean operator == (SqlSingle x, SqlSingle y)
272 if (x.IsNull || y .IsNull)
273 return SqlBoolean.Null;
274 return new SqlBoolean (x.Value == y.Value);
277 public static SqlBoolean operator > (SqlSingle x, SqlSingle y)
279 if (x.IsNull || y .IsNull)
280 return SqlBoolean.Null;
281 return new SqlBoolean (x.Value > y.Value);
284 public static SqlBoolean operator >= (SqlSingle x, SqlSingle y)
286 if (x.IsNull || y .IsNull)
287 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)
294 return SqlBoolean.Null;
295 return new SqlBoolean (!(x.Value == y.Value));
298 public static SqlBoolean operator < (SqlSingle x, SqlSingle y)
300 if (x.IsNull || y .IsNull)
301 return SqlBoolean.Null;
302 return new SqlBoolean (x.Value < y.Value);
305 public static SqlBoolean operator <= (SqlSingle x, SqlSingle y)
307 if (x.IsNull || y .IsNull)
308 return SqlBoolean.Null;
309 return new SqlBoolean (x.Value <= y.Value);
312 public static SqlSingle operator * (SqlSingle x, SqlSingle y)
314 float f = (float) (x.Value * y.Value);
316 if (Single.IsInfinity (f))
317 throw new OverflowException ();
319 return new SqlSingle (f);
322 public static SqlSingle operator - (SqlSingle x, SqlSingle y)
324 float f = (float) (x.Value - y.Value);
326 if (Single.IsInfinity (f))
327 throw new OverflowException ();
329 return new SqlSingle (f);
332 public static SqlSingle operator - (SqlSingle x)
334 return new SqlSingle (-(x.Value));
337 public static explicit operator SqlSingle (SqlBoolean x)
343 return new SqlSingle((float)x.ByteValue);
347 public static explicit operator SqlSingle (SqlDouble x)
352 float f = (float)x.Value;
354 if (Single.IsInfinity (f))
355 throw new OverflowException ();
357 return new SqlSingle(f);
360 public static explicit operator float (SqlSingle x)
365 public static explicit operator SqlSingle (SqlString x)
371 return SqlSingle.Parse (x.Value);
375 public static implicit operator SqlSingle (float x)
377 return new SqlSingle (x);
380 public static implicit operator SqlSingle (SqlByte x)
385 return new SqlSingle((float) x.Value);
388 public static implicit operator SqlSingle (SqlDecimal x)
393 return new SqlSingle((float) x.Value);
396 public static implicit operator SqlSingle (SqlInt16 x)
401 return new SqlSingle((float) x.Value);
404 public static implicit operator SqlSingle (SqlInt32 x)
409 return new SqlSingle((float) x.Value);
412 public static implicit operator SqlSingle (SqlInt64 x)
417 return new SqlSingle((float) x.Value);
420 public static implicit operator SqlSingle (SqlMoney x)
425 return new SqlSingle((float) x.Value);
429 public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
431 XmlQualifiedName qualifiedName = new XmlQualifiedName ("float", "http://www.w3.org/2001/XMLSchema");
432 return qualifiedName;
436 XmlSchema IXmlSerializable.GetSchema ()
438 throw new NotImplementedException ();
442 void IXmlSerializable.ReadXml (XmlReader reader)
444 throw new NotImplementedException ();
448 void IXmlSerializable.WriteXml (XmlWriter writer)
450 throw new NotImplementedException ();