Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlDouble.cs
Go to the documentation of this file.
5using System.Xml;
8
10
12[XmlSchemaProvider("GetXsdType")]
13[TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
15{
16 private bool m_fNotNull;
17
18 private double m_value;
19
20 public static readonly SqlDouble Null = new SqlDouble(fNull: true);
21
22 public static readonly SqlDouble Zero = new SqlDouble(0.0);
23
24 public static readonly SqlDouble MinValue = new SqlDouble(double.MinValue);
25
26 public static readonly SqlDouble MaxValue = new SqlDouble(double.MaxValue);
27
28 public bool IsNull => !m_fNotNull;
29
30 public double Value
31 {
32 get
33 {
34 if (m_fNotNull)
35 {
36 return m_value;
37 }
38 throw new SqlNullValueException();
39 }
40 }
41
42 private SqlDouble(bool fNull)
43 {
44 m_fNotNull = false;
45 m_value = 0.0;
46 }
47
48 public SqlDouble(double value)
49 {
50 if (!double.IsFinite(value))
51 {
53 }
54 m_value = value;
55 m_fNotNull = true;
56 }
57
58 public static implicit operator SqlDouble(double x)
59 {
60 return new SqlDouble(x);
61 }
62
63 public static explicit operator double(SqlDouble x)
64 {
65 return x.Value;
66 }
67
68 public override string ToString()
69 {
70 if (!IsNull)
71 {
72 return m_value.ToString((IFormatProvider?)null);
73 }
75 }
76
77 public static SqlDouble Parse(string s)
78 {
80 {
81 return Null;
82 }
83 return new SqlDouble(double.Parse(s, CultureInfo.InvariantCulture));
84 }
85
87 {
88 if (!x.IsNull)
89 {
90 return new SqlDouble(0.0 - x.m_value);
91 }
92 return Null;
93 }
94
96 {
97 if (x.IsNull || y.IsNull)
98 {
99 return Null;
100 }
101 double num = x.m_value + y.m_value;
102 if (double.IsInfinity(num))
103 {
105 }
106 return new SqlDouble(num);
107 }
108
110 {
111 if (x.IsNull || y.IsNull)
112 {
113 return Null;
114 }
115 double num = x.m_value - y.m_value;
116 if (double.IsInfinity(num))
117 {
119 }
120 return new SqlDouble(num);
121 }
122
124 {
125 if (x.IsNull || y.IsNull)
126 {
127 return Null;
128 }
129 double num = x.m_value * y.m_value;
130 if (double.IsInfinity(num))
131 {
133 }
134 return new SqlDouble(num);
135 }
136
138 {
139 if (x.IsNull || y.IsNull)
140 {
141 return Null;
142 }
143 if (y.m_value == 0.0)
144 {
146 }
147 double num = x.m_value / y.m_value;
148 if (double.IsInfinity(num))
149 {
151 }
152 return new SqlDouble(num);
153 }
154
155 public static explicit operator SqlDouble(SqlBoolean x)
156 {
157 if (!x.IsNull)
158 {
159 return new SqlDouble((int)x.ByteValue);
160 }
161 return Null;
162 }
163
164 public static implicit operator SqlDouble(SqlByte x)
165 {
166 if (!x.IsNull)
167 {
168 return new SqlDouble((int)x.Value);
169 }
170 return Null;
171 }
172
173 public static implicit operator SqlDouble(SqlInt16 x)
174 {
175 if (!x.IsNull)
176 {
177 return new SqlDouble(x.Value);
178 }
179 return Null;
180 }
181
182 public static implicit operator SqlDouble(SqlInt32 x)
183 {
184 if (!x.IsNull)
185 {
186 return new SqlDouble(x.Value);
187 }
188 return Null;
189 }
190
191 public static implicit operator SqlDouble(SqlInt64 x)
192 {
193 if (!x.IsNull)
194 {
195 return new SqlDouble(x.Value);
196 }
197 return Null;
198 }
199
200 public static implicit operator SqlDouble(SqlSingle x)
201 {
202 if (!x.IsNull)
203 {
204 return new SqlDouble(x.Value);
205 }
206 return Null;
207 }
208
209 public static implicit operator SqlDouble(SqlMoney x)
210 {
211 if (!x.IsNull)
212 {
213 return new SqlDouble(x.ToDouble());
214 }
215 return Null;
216 }
217
218 public static implicit operator SqlDouble(SqlDecimal x)
219 {
220 if (!x.IsNull)
221 {
222 return new SqlDouble(x.ToDouble());
223 }
224 return Null;
225 }
226
227 public static explicit operator SqlDouble(SqlString x)
228 {
229 if (x.IsNull)
230 {
231 return Null;
232 }
233 return Parse(x.Value);
234 }
235
237 {
238 if (!x.IsNull && !y.IsNull)
239 {
240 return new SqlBoolean(x.m_value == y.m_value);
241 }
242 return SqlBoolean.Null;
243 }
244
246 {
247 return !(x == y);
248 }
249
251 {
252 if (!x.IsNull && !y.IsNull)
253 {
254 return new SqlBoolean(x.m_value < y.m_value);
255 }
256 return SqlBoolean.Null;
257 }
258
260 {
261 if (!x.IsNull && !y.IsNull)
262 {
263 return new SqlBoolean(x.m_value > y.m_value);
264 }
265 return SqlBoolean.Null;
266 }
267
269 {
270 if (!x.IsNull && !y.IsNull)
271 {
272 return new SqlBoolean(x.m_value <= y.m_value);
273 }
274 return SqlBoolean.Null;
275 }
276
278 {
279 if (!x.IsNull && !y.IsNull)
280 {
281 return new SqlBoolean(x.m_value >= y.m_value);
282 }
283 return SqlBoolean.Null;
284 }
285
286 public static SqlDouble Add(SqlDouble x, SqlDouble y)
287 {
288 return x + y;
289 }
290
292 {
293 return x - y;
294 }
295
297 {
298 return x * y;
299 }
300
302 {
303 return x / y;
304 }
305
307 {
308 return x == y;
309 }
310
312 {
313 return x != y;
314 }
315
317 {
318 return x < y;
319 }
320
322 {
323 return x > y;
324 }
325
327 {
328 return x <= y;
329 }
330
332 {
333 return x >= y;
334 }
335
337 {
338 return (SqlBoolean)this;
339 }
340
342 {
343 return (SqlByte)this;
344 }
345
347 {
348 return (SqlInt16)this;
349 }
350
352 {
353 return (SqlInt32)this;
354 }
355
357 {
358 return (SqlInt64)this;
359 }
360
362 {
363 return (SqlMoney)this;
364 }
365
367 {
368 return (SqlDecimal)this;
369 }
370
372 {
373 return (SqlSingle)this;
374 }
375
377 {
378 return (SqlString)this;
379 }
380
381 public int CompareTo(object? value)
382 {
384 {
385 return CompareTo(value2);
386 }
387 throw ADP.WrongType(value.GetType(), typeof(SqlDouble));
388 }
389
391 {
392 if (IsNull)
393 {
394 if (!value.IsNull)
395 {
396 return -1;
397 }
398 return 0;
399 }
400 if (value.IsNull)
401 {
402 return 1;
403 }
404 if (this < value)
405 {
406 return -1;
407 }
408 if (this > value)
409 {
410 return 1;
411 }
412 return 0;
413 }
414
415 public override bool Equals([NotNullWhen(true)] object? value)
416 {
418 {
419 return false;
420 }
421 if (sqlDouble.IsNull || IsNull)
422 {
423 if (sqlDouble.IsNull)
424 {
425 return IsNull;
426 }
427 return false;
428 }
429 return (this == sqlDouble).Value;
430 }
431
432 public override int GetHashCode()
433 {
434 if (!IsNull)
435 {
436 return Value.GetHashCode();
437 }
438 return 0;
439 }
440
442 {
443 return null;
444 }
445
447 {
448 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
449 if (attribute != null && XmlConvert.ToBoolean(attribute))
450 {
451 reader.ReadElementString();
452 m_fNotNull = false;
453 }
454 else
455 {
457 m_fNotNull = true;
458 }
459 }
460
462 {
463 if (IsNull)
464 {
465 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
466 }
467 else
468 {
469 writer.WriteString(XmlConvert.ToString(m_value));
470 }
471 }
472
474 {
475 return new XmlQualifiedName("double", "http://www.w3.org/2001/XMLSchema");
476 }
477}
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static CultureInfo InvariantCulture
static bool ToBoolean(string s)
static string ToString(bool value)
static double ToDouble(string s)
string? GetAttribute(string name)
virtual string ReadElementString()
Definition XmlReader.cs:667
static readonly SqlBoolean Null
Definition SqlBoolean.cs:21
static SqlBoolean operator<(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:250
static readonly SqlDouble Zero
Definition SqlDouble.cs:22
static SqlDouble operator+(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:95
static readonly SqlDouble MinValue
Definition SqlDouble.cs:24
static SqlBoolean GreaterThan(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:321
static SqlBoolean operator>=(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:277
override string ToString()
Definition SqlDouble.cs:68
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlDouble.cs:473
static SqlBoolean Equals(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:306
static SqlBoolean operator!=(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:245
static SqlDouble Add(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:286
static SqlDouble Subtract(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:291
static SqlBoolean operator<=(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:268
static SqlBoolean LessThan(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:316
static readonly SqlDouble Null
Definition SqlDouble.cs:20
int CompareTo(object? value)
Definition SqlDouble.cs:381
static SqlDouble Parse(string s)
Definition SqlDouble.cs:77
static SqlBoolean NotEquals(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:311
static SqlBoolean operator>(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:259
static SqlDouble Divide(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:301
static SqlDouble operator-(SqlDouble x)
Definition SqlDouble.cs:86
static SqlBoolean LessThanOrEqual(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:326
static SqlDouble operator/(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:137
static readonly SqlDouble MaxValue
Definition SqlDouble.cs:26
static SqlBoolean operator==(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:236
override bool Equals([NotNullWhen(true)] object? value)
Definition SqlDouble.cs:415
static SqlDouble operator*(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:123
int CompareTo(SqlDouble value)
Definition SqlDouble.cs:390
static SqlBoolean GreaterThanOrEqual(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:331
static SqlDouble Multiply(SqlDouble x, SqlDouble y)
Definition SqlDouble.cs:296