2 // Mono.Data.TdsTypes.TdsDouble
5 // Tim Coleman <tim@timcoleman.com>
7 // (C) Copyright Tim Coleman, 2002
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.TdsClient;
33 using System.Data.SqlTypes;
34 using System.Globalization;
36 namespace Mono.Data.TdsTypes {
37 public struct TdsDouble : INullable, IComparable
44 public static readonly TdsDouble MaxValue = new TdsDouble (1.7976931348623157e308);
45 public static readonly TdsDouble MinValue = new TdsDouble (-1.7976931348623157e308);
46 public static readonly TdsDouble Null;
47 public static readonly TdsDouble Zero = new TdsDouble (0);
53 public TdsDouble (double value)
64 get { return !notNull; }
70 throw new TdsNullValueException ();
80 public static TdsDouble Add (TdsDouble x, TdsDouble y)
85 public int CompareTo (object value)
89 else if (!(value is TdsDouble))
90 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.TdsTypes.TdsDouble"));
91 else if (((TdsDouble)value).IsNull)
94 return this.value.CompareTo (((TdsDouble)value).Value);
97 public static TdsDouble Divide (TdsDouble x, TdsDouble y)
102 public override bool Equals (object value)
104 if (!(value is TdsDouble))
107 return (bool) (this == (TdsDouble)value);
110 public static TdsBoolean Equals (TdsDouble x, TdsDouble y)
115 public override int GetHashCode ()
117 long LongValue = (long)value;
118 return (int)(LongValue ^ (LongValue >> 32));
122 public static TdsBoolean GreaterThan (TdsDouble x, TdsDouble y)
127 public static TdsBoolean GreaterThanOrEqual (TdsDouble x, TdsDouble y)
132 public static TdsBoolean LessThan (TdsDouble x, TdsDouble y)
137 public static TdsBoolean LessThanOrEqual (TdsDouble x, TdsDouble y)
142 public static TdsDouble Multiply (TdsDouble x, TdsDouble y)
147 public static TdsBoolean NotEquals (TdsDouble x, TdsDouble y)
152 public static TdsDouble Parse (string s)
154 return new TdsDouble (Double.Parse (s));
157 public static TdsDouble Subtract (TdsDouble x, TdsDouble y)
162 public TdsBoolean ToTdsBoolean ()
164 return ((TdsBoolean)this);
167 public TdsByte ToTdsByte ()
169 return ((TdsByte)this);
172 public TdsDecimal ToTdsDecimal ()
174 return ((TdsDecimal)this);
177 public TdsInt16 ToTdsInt16 ()
179 return ((TdsInt16)this);
182 public TdsInt32 ToTdsInt32 ()
184 return ((TdsInt32)this);
187 public TdsInt64 ToTdsInt64 ()
189 return ((TdsInt64)this);
192 public TdsMoney ToTdsMoney ()
194 return ((TdsMoney)this);
197 public TdsSingle ToTdsSingle ()
199 return ((TdsSingle)this);
202 public TdsString ToTdsString ()
204 return ((TdsString)this);
207 public override string ToString ()
212 return value.ToString ();
215 public static TdsDouble operator + (TdsDouble x, TdsDouble y)
217 return new TdsDouble (x.Value + y.Value);
220 public static TdsDouble operator / (TdsDouble x, TdsDouble y)
222 return new TdsDouble (x.Value / y.Value);
225 public static TdsBoolean operator == (TdsDouble x, TdsDouble y)
227 if (x.IsNull || y.IsNull)
228 return TdsBoolean.Null;
230 return new TdsBoolean (x.Value == y.Value);
233 public static TdsBoolean operator > (TdsDouble x, TdsDouble y)
235 if (x.IsNull || y.IsNull)
236 return TdsBoolean.Null;
238 return new TdsBoolean (x.Value > y.Value);
241 public static TdsBoolean operator >= (TdsDouble x, TdsDouble y)
243 if (x.IsNull || y.IsNull)
244 return TdsBoolean.Null;
246 return new TdsBoolean (x.Value >= y.Value);
249 public static TdsBoolean operator != (TdsDouble x, TdsDouble y)
251 if (x.IsNull || y.IsNull)
252 return TdsBoolean.Null;
254 return new TdsBoolean (!(x.Value == y.Value));
257 public static TdsBoolean operator < (TdsDouble x, TdsDouble y)
259 if (x.IsNull || y.IsNull)
260 return TdsBoolean.Null;
262 return new TdsBoolean (x.Value < y.Value);
265 public static TdsBoolean operator <= (TdsDouble x, TdsDouble y)
267 if (x.IsNull || y.IsNull)
268 return TdsBoolean.Null;
270 return new TdsBoolean (x.Value <= y.Value);
273 public static TdsDouble operator * (TdsDouble x, TdsDouble y)
275 return new TdsDouble (x.Value * y.Value);
278 public static TdsDouble operator - (TdsDouble x, TdsDouble y)
280 return new TdsDouble (x.Value - y.Value);
283 public static TdsDouble operator - (TdsDouble n)
285 return new TdsDouble (-(n.Value));
288 public static explicit operator TdsDouble (TdsBoolean x)
293 return new TdsDouble ((double)x.ByteValue);
296 public static explicit operator double (TdsDouble x)
301 public static explicit operator TdsDouble (TdsString x)
303 return TdsDouble.Parse (x.Value);
306 public static implicit operator TdsDouble (double x)
308 return new TdsDouble (x);
311 public static implicit operator TdsDouble (TdsByte x)
316 return new TdsDouble ((double)x.Value);
319 public static implicit operator TdsDouble (TdsDecimal x)
324 return new TdsDouble ((double)x.Value);
327 public static implicit operator TdsDouble (TdsInt16 x)
332 return new TdsDouble ((double)x.Value);
335 public static implicit operator TdsDouble (TdsInt32 x)
340 return new TdsDouble ((double)x.Value);
343 public static implicit operator TdsDouble (TdsInt64 x)
348 return new TdsDouble ((double)x.Value);
351 public static implicit operator TdsDouble (TdsMoney x)
356 return new TdsDouble ((double)x.Value);
359 public static implicit operator TdsDouble (TdsSingle x)
364 return new TdsDouble ((double)x.Value);