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 using System.Globalization;
14 namespace System.Data.SqlTypes
16 public struct SqlSingle : INullable, IComparable
24 public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859E+38f);
25 public static readonly SqlSingle MinValue = new SqlSingle (-3.40282346638528859E+38f);
26 public static readonly SqlSingle Null;
27 public static readonly SqlSingle Zero = new SqlSingle (0);
33 public SqlSingle (double value)
35 this.value = (float)value;
39 public SqlSingle (float value)
50 get { return !notNull; }
56 throw new SqlNullValueException ();
66 public static SqlSingle Add (SqlSingle x, SqlSingle y)
71 public int CompareTo (object value)
75 else if (!(value is SqlSingle))
76 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlSingle"));
77 else if (((SqlSingle)value).IsNull)
80 return this.value.CompareTo (((SqlSingle)value).Value);
83 public static SqlSingle Divide (SqlSingle x, SqlSingle y)
88 public override bool Equals (object value)
90 if (!(value is SqlSingle))
92 else if (this.IsNull && ((SqlSingle)value).IsNull)
94 else if (((SqlSingle)value).IsNull)
97 return (bool) (this == (SqlSingle)value);
100 public static SqlBoolean Equals (SqlSingle x, SqlSingle y)
105 public override int GetHashCode ()
107 long LongValue = (long) value;
108 return (int)(LongValue ^ (LongValue >> 32));
111 public static SqlBoolean GreaterThan (SqlSingle x, SqlSingle y)
116 public static SqlBoolean GreaterThanOrEqual (SqlSingle x, SqlSingle y)
121 public static SqlBoolean LessThan (SqlSingle x, SqlSingle y)
126 public static SqlBoolean LessThanOrEqual (SqlSingle x, SqlSingle y)
131 public static SqlSingle Multiply (SqlSingle x, SqlSingle y)
136 public static SqlBoolean NotEquals (SqlSingle x, SqlSingle y)
141 public static SqlSingle Parse (string s)
143 return new SqlSingle (Single.Parse (s));
146 public static SqlSingle Subtract (SqlSingle x, SqlSingle y)
151 public SqlBoolean ToSqlBoolean ()
153 return ((SqlBoolean)this);
156 public SqlByte ToSqlByte ()
158 return ((SqlByte)this);
161 public SqlDecimal ToSqlDecimal ()
163 return ((SqlDecimal)this);
166 public SqlDouble ToSqlDouble ()
168 return ((SqlDouble)this);
171 public SqlInt16 ToSqlInt16 ()
173 return ((SqlInt16)this);
176 public SqlInt32 ToSqlInt32 ()
178 return ((SqlInt32)this);
181 public SqlInt64 ToSqlInt64 ()
183 return ((SqlInt64)this);
186 public SqlMoney ToSqlMoney ()
188 return ((SqlMoney)this);
192 public SqlString ToSqlString ()
194 return ((SqlString)this);
197 public override string ToString ()
199 return value.ToString ();
202 public static SqlSingle operator + (SqlSingle x, SqlSingle y)
204 float f = (float)(x.Value + y.Value);
206 if (Single.IsInfinity (f))
207 throw new OverflowException ();
209 return new SqlSingle (f);
212 public static SqlSingle operator / (SqlSingle x, SqlSingle y)
214 float f = (float)(x.Value / y.Value);
216 if (Single.IsInfinity (f)) {
219 throw new DivideByZeroException ();
222 return new SqlSingle (x.Value / y.Value);
225 public static SqlBoolean operator == (SqlSingle x, SqlSingle y)
227 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
228 return new SqlBoolean (x.Value == y.Value);
231 public static SqlBoolean operator > (SqlSingle x, SqlSingle y)
233 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
234 return new SqlBoolean (x.Value > y.Value);
237 public static SqlBoolean operator >= (SqlSingle x, SqlSingle y)
239 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
240 return new SqlBoolean (x.Value >= y.Value);
243 public static SqlBoolean operator != (SqlSingle x, SqlSingle y)
245 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
246 return new SqlBoolean (!(x.Value == y.Value));
249 public static SqlBoolean operator < (SqlSingle x, SqlSingle y)
251 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
252 return new SqlBoolean (x.Value < y.Value);
255 public static SqlBoolean operator <= (SqlSingle x, SqlSingle y)
257 if (x.IsNull || y .IsNull) return SqlBoolean.Null;
258 return new SqlBoolean (x.Value <= y.Value);
261 public static SqlSingle operator * (SqlSingle x, SqlSingle y)
263 float f = (float)(x.Value * y.Value);
265 if (Single.IsInfinity (f))
266 throw new OverflowException ();
268 return new SqlSingle (f);
271 public static SqlSingle operator - (SqlSingle x, SqlSingle y)
273 float f = (float)(x.Value - y.Value);
275 if (Single.IsInfinity (f))
276 throw new OverflowException ();
278 return new SqlSingle (f);
281 public static SqlSingle operator - (SqlSingle n)
283 return new SqlSingle (-(n.Value));
286 public static explicit operator SqlSingle (SqlBoolean x)
292 return new SqlSingle((float)x.ByteValue);
296 public static explicit operator SqlSingle (SqlDouble x)
301 float f = (float)x.Value;
303 if (Single.IsInfinity (f))
304 throw new OverflowException ();
306 return new SqlSingle(f);
309 public static explicit operator float (SqlSingle x)
314 public static explicit operator SqlSingle (SqlString x)
320 return SqlSingle.Parse (x.Value);
324 public static implicit operator SqlSingle (float x)
326 return new SqlSingle (x);
329 public static implicit operator SqlSingle (SqlByte x)
334 return new SqlSingle((float)x.Value);
337 public static implicit operator SqlSingle (SqlDecimal x)
342 return new SqlSingle((float)x.Value);
345 public static implicit operator SqlSingle (SqlInt16 x)
350 return new SqlSingle((float)x.Value);
353 public static implicit operator SqlSingle (SqlInt32 x)
358 return new SqlSingle((float)x.Value);
361 public static implicit operator SqlSingle (SqlInt64 x)
366 return new SqlSingle((float)x.Value);
369 public static implicit operator SqlSingle (SqlMoney x)
374 return new SqlSingle((float)x.Value);