DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlNumber.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
20 using Deveel.Math;
21 
22 namespace Deveel.Data.Sql.Objects {
23  [Serializable]
24  public struct SqlNumber : ISqlObject, IComparable<SqlNumber>, IConvertible, IEquatable<SqlNumber>, ISerializable {
25  private readonly BigDecimal innerValue;
26  private readonly int byteCount;
27  private readonly long valueAsLong;
28 
29  public static readonly SqlNumber Zero = new SqlNumber(NumericState.None, BigDecimal.Zero);
30  public static readonly SqlNumber One = new SqlNumber(NumericState.None, BigDecimal.One);
31  public static readonly SqlNumber Null = new SqlNumber(NumericState.None, null);
32 
33  public static readonly SqlNumber NaN = new SqlNumber(NumericState.NotANumber, null);
34 
35  public static readonly SqlNumber NegativeInfinity = new SqlNumber(NumericState.NegativeInfinity, null);
36 
37  public static readonly SqlNumber PositiveInfinity = new SqlNumber(NumericState.PositiveInfinity, null);
38 
39  private SqlNumber(BigDecimal value)
40  : this(NumericState.None, value) {
41  }
42 
43  private SqlNumber(NumericState state, BigDecimal value)
44  : this() {
45  valueAsLong = 0;
46  byteCount = 120;
47 
48  if (value != null && value.Scale == 0) {
49  BigInteger bint = value.ToBigInteger();
50  int bitCount = bint.BitLength;
51  if (bitCount < 30) {
52  valueAsLong = bint.ToInt64();
53  byteCount = 4;
54  } else if (bitCount < 60) {
55  valueAsLong = bint.ToInt64();
56  byteCount = 8;
57  }
58  }
59 
60  innerValue = value;
61  State = state;
62  }
63 
64  public SqlNumber(byte[] bytes, int scale)
65  : this(new BigDecimal(new BigInteger(bytes), scale)) {
66  }
67 
68  public SqlNumber(byte[] bytes, int scale, int precision)
69  : this(new BigDecimal(new BigInteger(bytes), scale, new MathContext(precision))) {
70  }
71 
72  public SqlNumber(int value, int precision)
73  : this(new BigDecimal(value, new MathContext(precision))) {
74  }
75 
76  public SqlNumber(int value)
77  : this(value, MathContext.Decimal32.Precision) {
78  }
79 
80  public SqlNumber(long value, int precision)
81  : this(new BigDecimal(value, new MathContext(precision))) {
82  }
83 
84  public SqlNumber(long value)
85  : this(value, MathContext.Decimal64.Precision) {
86  }
87 
88  public SqlNumber(double value)
89  : this(value, MathContext.Decimal128.Precision) {
90  }
91 
92  public SqlNumber(double value, int precision)
93  : this(new BigDecimal(value, new MathContext(precision))) {
94  }
95 
96  private SqlNumber(ObjectData data)
97  : this() {
98  var state = (NumericState) data.GetByte("State");
99 
100  if (state == NumericState.None) {
101  var bytes = data.GetValue<byte[]>("Bytes");
102  var scale = data.GetInt32("Scale");
103  var precision = data.GetInt32("Precision");
104 
105  innerValue = new BigDecimal(new BigInteger(bytes), scale, new MathContext(precision));
106  }
107 
108  State = state;
109  }
110 
111  public NumericState State { get; private set; }
112 
113  public bool CanBeInt64 {
114  get { return byteCount <= 8; }
115  }
116 
117  public bool CanBeInt32 {
118  get { return byteCount <= 4; }
119  }
120 
121  public int Scale {
122  get { return State == NumericState.None ? innerValue.Scale : 0; }
123  }
124 
125  public int Precision {
126  get { return State == NumericState.None ? innerValue.Precision : 0; }
127  }
128 
129  private MathContext MathContext {
130  get { return State == NumericState.None ? new MathContext(Precision) : null; }
131  }
132 
133  public int Sign {
134  get { return State == NumericState.None ? innerValue.Sign : 0; }
135  }
136 
138  data.SetValue("State", (byte)State);
139 
140  if (State == NumericState.None) {
141  var bytes = innerValue.UnscaledValue.ToByteArray();
142  var scale = innerValue.Scale;
143  var precision = innerValue.Precision;
144 
145  data.SetValue("Bytes", bytes);
146  data.SetValue("Scale", scale);
147  data.SetValue("Precision", precision);
148  }
149  }
150 
151  int IComparable.CompareTo(object obj) {
152  if (!(obj is SqlNumber))
153  throw new ArgumentException();
154 
155  return CompareTo((SqlNumber) obj);
156  }
157 
158  int IComparable<ISqlObject>.CompareTo(ISqlObject other) {
159  if (!(other is SqlNumber))
160  throw new ArgumentException();
161 
162  return CompareTo((SqlNumber) other);
163  }
164 
165  public bool IsNull {
166  get { return State == NumericState.None && innerValue == null; }
167  }
168 
170  if (State == NumericState.NegativeInfinity)
171  return NumericState.PositiveInfinity;
172  if (State == NumericState.PositiveInfinity)
173  return NumericState.NegativeInfinity;
174  return State;
175  }
176 
178  return other is SqlNumber;
179  }
180 
181  public bool Equals(SqlNumber other) {
182  if (State == NumericState.NegativeInfinity &&
183  other.State == NumericState.NegativeInfinity)
184  return true;
185  if (State == NumericState.PositiveInfinity &&
186  other.State == NumericState.PositiveInfinity)
187  return true;
188  if (State == NumericState.NotANumber &&
189  other.State == NumericState.NotANumber)
190  return true;
191 
192  if (IsNull && other.IsNull)
193  return true;
194  if (IsNull && !other.IsNull)
195  return false;
196  if (!IsNull && other.IsNull)
197  return false;
198 
199  return innerValue.CompareTo(other.innerValue) == 0;
200  }
201 
202  public override bool Equals(object obj) {
203  if (!(obj is SqlNumber))
204  return false;
205 
206  return Equals((SqlNumber) obj);
207  }
208 
209  public override int GetHashCode() {
210  return innerValue.GetHashCode() ^ State.GetHashCode();
211  }
212 
213  public int CompareTo(SqlNumber other) {
214  if (Equals(this, other))
215  return 0;
216 
217  // If this is a non-infinity number
218  if (State == NumericState.None) {
219  // If both values can be represented by a long value
220  if (CanBeInt64 && other.CanBeInt64) {
221  // Perform a long comparison check,
222  return valueAsLong.CompareTo(other.valueAsLong);
223  }
224 
225  // And the compared number is non-infinity then use the BigDecimal
226  // compareTo method.
227  if (other.State == NumericState.None)
228  return innerValue.CompareTo(other.innerValue);
229 
230  // Comparing a regular number with a NaN number.
231  // If positive infinity or if NaN
232  if (other.State == NumericState.PositiveInfinity ||
233  other.State == NumericState.NotANumber) {
234  return -1;
235  }
236  // If negative infinity
237  if (other.State == NumericState.NegativeInfinity)
238  return 1;
239 
240  throw new ArgumentException("Unknown number state.");
241  }
242 
243  // This number is a NaN number.
244  // Are we comparing with a regular number?
245  if (other.State == NumericState.None) {
246  // Yes, negative infinity
247  if (State == NumericState.NegativeInfinity)
248  return -1;
249 
250  // positive infinity or NaN
251  if (State == NumericState.PositiveInfinity ||
252  State == NumericState.NotANumber)
253  return 1;
254 
255  throw new ArgumentException("Unknown number state.");
256  }
257 
258  // Comparing NaN number with a NaN number.
259  // This compares -Inf less than Inf and NaN and NaN greater than
260  // Inf and -Inf. -Inf < Inf < NaN
261  return (State - other.State);
262  }
263 
264  TypeCode IConvertible.GetTypeCode() {
265  if (CanBeInt32)
266  return TypeCode.Int32;
267  if (CanBeInt64)
268  return TypeCode.Int64;
269 
270  return TypeCode.Object;
271  }
272 
273  bool IConvertible.ToBoolean(IFormatProvider provider) {
274  return ToBoolean();
275  }
276 
277  char IConvertible.ToChar(IFormatProvider provider) {
278  throw new InvalidCastException("Conversion of NUMERIC to Char is invalid.");
279  }
280 
281  sbyte IConvertible.ToSByte(IFormatProvider provider) {
282  throw new NotSupportedException("Conversion to Signed Byte numbers not supported yet.");
283  }
284 
285  byte IConvertible.ToByte(IFormatProvider provider) {
286  return ToByte();
287  }
288 
289  short IConvertible.ToInt16(IFormatProvider provider) {
290  return ToInt16();
291  }
292 
293  ushort IConvertible.ToUInt16(IFormatProvider provider) {
294  throw new NotSupportedException("Conversion to Unsigned numbers not supported yet.");
295  }
296 
297  int IConvertible.ToInt32(IFormatProvider provider) {
298  return ToInt32();
299  }
300 
301  uint IConvertible.ToUInt32(IFormatProvider provider) {
302  throw new NotSupportedException("Conversion to Unsigned numbers not supported yet.");
303  }
304 
305  long IConvertible.ToInt64(IFormatProvider provider) {
306  return ToInt64();
307  }
308 
309  ulong IConvertible.ToUInt64(IFormatProvider provider) {
310  throw new NotSupportedException("Conversion to Unsigned numbers not supported yet.");
311  }
312 
313  float IConvertible.ToSingle(IFormatProvider provider) {
314  return ToSingle();
315  }
316 
317  double IConvertible.ToDouble(IFormatProvider provider) {
318  return ToDouble();
319  }
320 
321  decimal IConvertible.ToDecimal(IFormatProvider provider) {
322  throw new NotSupportedException("Conversion to Decimal not supported yet.");
323  }
324 
325  DateTime IConvertible.ToDateTime(IFormatProvider provider) {
326  throw new InvalidCastException("Cannot cast NUMERIC to DateTime automatically.");
327  }
328 
329  string IConvertible.ToString(IFormatProvider provider) {
330  return ToString();
331  }
332 
333  object IConvertible.ToType(Type conversionType, IFormatProvider provider) {
334  if (conversionType == typeof (bool))
335  return ToBoolean();
336  if (conversionType == typeof (byte))
337  return ToByte();
338  if (conversionType == typeof (short))
339  return ToInt16();
340  if (conversionType == typeof (int))
341  return ToInt32();
342  if (conversionType == typeof (long))
343  return ToInt64();
344  if (conversionType == typeof (float))
345  return ToSingle();
346  if (conversionType == typeof (double))
347  return ToDouble();
348 
349  if (conversionType == typeof (byte[]))
350  return ToByteArray();
351 
352  if (conversionType == typeof (string))
353  return ToString();
354 
355  if (conversionType == typeof (SqlBoolean))
356  return new SqlBoolean(ToBoolean());
357  if (conversionType == typeof (SqlBinary))
358  return new SqlBinary(ToByteArray());
359  if (conversionType == typeof (SqlString))
360  return new SqlString(ToString());
361 
362  throw new InvalidCastException(System.String.Format("Cannot convert NUMERIC to {0}", conversionType));
363  }
364 
365  public byte[] ToByteArray() {
366  return State == NumericState.None
367  ? innerValue.MovePointRight(innerValue.Scale).ToBigInteger().ToByteArray()
368  : new byte[0];
369  }
370 
371  public override string ToString() {
372  switch (State) {
373  case (NumericState.None):
374  return innerValue.ToString();
375  case (NumericState.NegativeInfinity):
376  return "-Infinity";
377  case (NumericState.PositiveInfinity):
378  return "Infinity";
379  case (NumericState.NotANumber):
380  return "NaN";
381  default:
382  throw new InvalidCastException("Unknown number state");
383  }
384  }
385 
386  public double ToDouble() {
387  switch (State) {
388  case (NumericState.None):
389  return innerValue.ToDouble();
390  case (NumericState.NegativeInfinity):
391  return Double.NegativeInfinity;
392  case (NumericState.PositiveInfinity):
393  return Double.PositiveInfinity;
394  case (NumericState.NotANumber):
395  return Double.NaN;
396  default:
397  throw new InvalidCastException("Unknown number state");
398  }
399  }
400 
401  public float ToSingle() {
402  switch (State) {
403  case (NumericState.None):
404  return innerValue.ToSingle();
405  case (NumericState.NegativeInfinity):
406  return Single.NegativeInfinity;
407  case (NumericState.PositiveInfinity):
408  return Single.PositiveInfinity;
409  case (NumericState.NotANumber):
410  return Single.NaN;
411  default:
412  throw new InvalidCastException("Unknown number state");
413  }
414  }
415 
416  public long ToInt64() {
417  if (CanBeInt64)
418  return valueAsLong;
419  switch (State) {
420  case (NumericState.None):
421  return innerValue.ToInt64();
422  default:
423  return (long)ToDouble();
424  }
425  }
426 
427  public int ToInt32() {
428  if (CanBeInt32)
429  return (int)valueAsLong;
430  switch (State) {
431  case (NumericState.None):
432  return innerValue.ToInt32();
433  default:
434  return (int)ToDouble();
435  }
436  }
437 
438  public short ToInt16() {
439  if (!CanBeInt32)
440  throw new InvalidCastException("The value of this numeric is over the maximum Int16.");
441 
442  var value = ToInt32();
443  if (value > Int16.MaxValue ||
444  value < Int16.MinValue)
445  throw new InvalidCastException("The value of this numeric is out of range of a short integer.");
446 
447  return (short)value;
448  }
449 
450  public byte ToByte() {
451  if (!CanBeInt32)
452  throw new InvalidCastException("The value of this numeric is over the maximum Byte.");
453 
454  var value = ToInt32();
455  if (value > Byte.MaxValue ||
456  value < Byte.MinValue)
457  throw new InvalidCastException("The value of this numeric is out of range of a byte.");
458 
459  return (byte)value;
460  }
461 
462  public bool ToBoolean() {
463  if (Equals(One))
464  return true;
465  if (Equals(Zero))
466  return false;
467 
468  throw new InvalidCastException("The value of this NUMERIC cannot be converted to a boolean.");
469  }
470 
471  public SqlNumber XOr(SqlNumber value) {
472  if (State == NumericState.NotANumber)
473  return this;
474 
475  if (Scale == 0 && value.Scale == 0) {
476  BigInteger bi1 = innerValue.ToBigInteger();
477  BigInteger bi2 = value.innerValue.ToBigInteger();
478  return new SqlNumber(NumericState.None, new BigDecimal(bi1.XOr(bi2)));
479  }
480 
481  return Null;
482  }
483 
484  public SqlNumber And(SqlNumber value) {
485  if (State == NumericState.NotANumber)
486  return this;
487 
488  if (Scale == 0 && value.Scale == 0) {
489  BigInteger bi1 = innerValue.ToBigInteger();
490  BigInteger bi2 = value.innerValue.ToBigInteger();
491  return new SqlNumber(NumericState.None, new BigDecimal(bi1.And(bi2)));
492  }
493 
494  return Null;
495  }
496 
497  public SqlNumber Or(SqlNumber value) {
498  if (State == NumericState.NotANumber)
499  return this;
500 
501  if (Scale == 0 && value.Scale == 0) {
502  BigInteger bi1 = innerValue.ToBigInteger();
503  BigInteger bi2 = value.innerValue.ToBigInteger();
504  return new SqlNumber(NumericState.None, new BigDecimal(bi1.Or(bi2)));
505  }
506 
507  return Null;
508  }
509 
510  public SqlNumber Add(SqlNumber value) {
511  if (State == NumericState.None) {
512  if (value.State == NumericState.None) {
513  if (IsNull || value.IsNull)
514  return Null;
515 
516  return new SqlNumber(NumericState.None, innerValue.Add(value.innerValue));
517  }
518 
519  return new SqlNumber(value.State, null);
520  }
521 
522  return new SqlNumber(State, null);
523  }
524 
525  public SqlNumber Subtract(SqlNumber value) {
526  if (State == NumericState.None) {
527  if (value.State == NumericState.None) {
528  if (IsNull || value.IsNull)
529  return Null;
530 
531  return new SqlNumber(NumericState.None, innerValue.Subtract(value.innerValue));
532  }
533  return new SqlNumber(value.InverseState(), null);
534  }
535 
536  return new SqlNumber(State, null);
537  }
538 
539  public SqlNumber Multiply(SqlNumber value) {
540  if (State == NumericState.None) {
541  if (value.State == NumericState.None) {
542  if (IsNull || value.IsNull)
543  return Null;
544 
545  return new SqlNumber(NumericState.None, innerValue.Multiply(value.innerValue));
546  }
547 
548  return new SqlNumber(value.State, null);
549  }
550 
551  return new SqlNumber(State, null);
552  }
553 
554  public SqlNumber Divide(SqlNumber value) {
555  if (State == NumericState.None) {
556  if (value.State == NumericState.None) {
557  if (IsNull || value.IsNull)
558  return Null;
559 
560  BigDecimal divBy = value.innerValue;
561  if (divBy.CompareTo (BigDecimal.Zero) != 0) {
562  return new SqlNumber(NumericState.None, innerValue.Divide(divBy, 10, RoundingMode.HalfUp));
563  }
564  }
565  }
566 
567  // Return NaN if we can't divide
568  return new SqlNumber(NumericState.NotANumber, null);
569  }
570 
571  public SqlNumber Modulo(SqlNumber value) {
572  if (State == NumericState.None) {
573  if (value.State == NumericState.None) {
574  if (IsNull || value.IsNull)
575  return Null;
576 
577  BigDecimal divBy = value.innerValue;
578  if (divBy.CompareTo(BigDecimal.Zero) != 0) {
579  BigDecimal remainder = innerValue.Remainder(divBy);
580  return new SqlNumber(NumericState.None, remainder);
581  }
582  }
583  }
584 
585  return new SqlNumber(NumericState.NotANumber, null);
586  }
587 
588  public SqlNumber Abs() {
589  if (State == NumericState.None)
590  return new SqlNumber(NumericState.None, innerValue.Abs());
591  if (State == NumericState.NegativeInfinity)
592  return new SqlNumber(NumericState.PositiveInfinity, null);
593  return new SqlNumber(State, null);
594  }
595 
596  [CLSCompliant(false)]
597  public SqlNumber SetScale(int scale, RoundingMode mode) {
598  if (State == NumericState.None)
599  return new SqlNumber(innerValue.SetScale(scale, mode));
600 
601  // Can't round -inf, +inf and NaN
602  return this;
603  }
604 
605  public SqlNumber Negate() {
606  if (State == NumericState.None)
607  return new SqlNumber(innerValue.Negate());
608  if (State == NumericState.NegativeInfinity ||
609  State == NumericState.PositiveInfinity)
610  return new SqlNumber(InverseState(), null);
611 
612  return this;
613  }
614 
615  public SqlNumber Plus() {
616  if (State == NumericState.None)
617  return new SqlNumber(innerValue.Plus());
618  if (State == NumericState.NegativeInfinity ||
619  State == NumericState.PositiveInfinity)
620  return new SqlNumber(InverseState(), null);
621 
622  return this;
623  }
624 
625  public SqlNumber Not() {
626  if (State == NumericState.None)
627  return new SqlNumber(new BigDecimal(innerValue.ToBigInteger().Not()));
628  if (State == NumericState.NegativeInfinity ||
629  State == NumericState.PositiveInfinity)
630  return new SqlNumber(InverseState(), null);
631 
632  return this;
633  }
634 
635  public SqlNumber Sqrt() {
636  if (State == NumericState.None)
637  return new SqlNumber(BigMath.Sqrt(innerValue));
638 
639  return this;
640  }
641 
642  public SqlNumber Root(int n) {
643  if (State == NumericState.None)
644  return new SqlNumber(BigMath.Root(n, innerValue));
645 
646  return this;
647  }
648 
649  public SqlNumber Sin() {
650  if (State == NumericState.None)
651  return new SqlNumber(BigMath.Sin(innerValue));
652 
653  return this;
654  }
655 
656  public SqlNumber Cos() {
657  if (State == NumericState.None)
658  return new SqlNumber(BigMath.Cos(innerValue));
659 
660  return this;
661  }
662 
663  public SqlNumber Cot() {
664  if (State == NumericState.None)
665  return new SqlNumber(BigMath.Cot(innerValue));
666 
667  return this;
668  }
669 
670  public SqlNumber Tan() {
671  if (State == NumericState.None)
672  return new SqlNumber(BigMath.Tan(innerValue));
673 
674  return this;
675  }
676 
677  public SqlNumber Pow(SqlNumber exp) {
678  if (State == NumericState.None)
679  return new SqlNumber(BigMath.Pow(innerValue, exp.innerValue));
680 
681  return this;
682  }
683 
684  public SqlNumber Log2() {
685  if (State == NumericState.None)
686  return new SqlNumber(BigMath.Log(innerValue));
687 
688  return this;
689  }
690 
691  public SqlNumber Round() {
692  return Round(MathContext.Precision);
693  }
694 
695  public SqlNumber Round(int precision) {
696  if (State == NumericState.None)
697  return new SqlNumber(innerValue.Round(new MathContext(precision, RoundingMode.HalfUp)));
698 
699  return this;
700  }
701 
702  public static bool TryParse(string s, out SqlNumber value) {
703  if (String.IsNullOrEmpty(s)) {
704  value = Null;
705  return false;
706  }
707 
708  if (string.Equals(s, "+Infinity", StringComparison.OrdinalIgnoreCase) ||
709  string.Equals(s, "+Inf", StringComparison.OrdinalIgnoreCase) ||
710  string.Equals(s, "Infinity", StringComparison.OrdinalIgnoreCase)) {
711  value = PositiveInfinity;
712  return true;
713  }
714 
715  if (string.Equals(s, "-Infinity", StringComparison.OrdinalIgnoreCase) ||
716  string.Equals(s, "-Inf", StringComparison.OrdinalIgnoreCase)) {
717  value = NegativeInfinity;
718  return true;
719  }
720 
721  if (string.Equals(s, "NaN", StringComparison.OrdinalIgnoreCase) ||
722  string.Equals(s, "NotANumber", StringComparison.OrdinalIgnoreCase)) {
723  value = NaN;
724  return true;
725  }
726 
727  BigDecimal decimalValue;
728 
729  if (!BigDecimal.TryParse(s, out decimalValue)) {
730  value = Null;
731  return false;
732  }
733 
734  value = new SqlNumber(NumericState.None, decimalValue);
735  return true;
736  }
737 
738  public static SqlNumber Parse(string s) {
739  SqlNumber value;
740  if (!TryParse(s, out value))
741  throw new FormatException(string.Format("Cannot parse the string '{0}' to a valid Numeric object.", s));
742 
743  return value;
744  }
745 
746  public static SqlNumber operator +(SqlNumber a, SqlNumber b) {
747  return a.Add(b);
748  }
749 
750  public static SqlNumber operator -(SqlNumber a, SqlNumber b) {
751  return a.Subtract(b);
752  }
753 
754  public static SqlNumber operator *(SqlNumber a, SqlNumber b) {
755  return a.Multiply(b);
756  }
757 
758  public static SqlNumber operator /(SqlNumber a, SqlNumber b) {
759  return a.Divide(b);
760  }
761 
762  public static SqlNumber operator %(SqlNumber a, SqlNumber b) {
763  return a.Modulo(b);
764  }
765 
766  public static SqlNumber operator |(SqlNumber a, SqlNumber b) {
767  return a.XOr(b);
768  }
769 
770  public static SqlNumber operator -(SqlNumber a) {
771  return a.Negate();
772  }
773 
774  public static SqlNumber operator +(SqlNumber a) {
775  return a.Plus();
776  }
777 
778  public static bool operator ==(SqlNumber a, SqlNumber b) {
779  return a.Equals(b);
780  }
781 
782  public static bool operator !=(SqlNumber a, SqlNumber b) {
783  return !(a == b);
784  }
785 
786  public static bool operator >(SqlNumber a, SqlNumber b) {
787  return a.CompareTo(b) > 0;
788  }
789 
790  public static bool operator <(SqlNumber a, SqlNumber b) {
791  return a.CompareTo(b) < 0;
792  }
793 
794  public static bool operator >=(SqlNumber a, SqlNumber b) {
795  var i = a.CompareTo(b);
796  return i == 0 || i > 0;
797  }
798 
799  public static bool operator <=(SqlNumber a, SqlNumber b) {
800  var i = a.CompareTo(b);
801  return i == 0 || i < 0;
802  }
803  }
804 }
NumericState
Lists all the possible special states of a number.
Definition: NumericState.cs:21
void GetData(SerializeData data)
SqlNumber XOr(SqlNumber value)
Definition: SqlNumber.cs:471
bool Equals(SqlNumber other)
Definition: SqlNumber.cs:181
SqlNumber(long value, int precision)
Definition: SqlNumber.cs:80
The number represents a negative infinity (for example, the result of a division of a negative number...
static bool TryParse(string s, out SqlNumber value)
Definition: SqlNumber.cs:702
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
int CompareTo(SqlNumber other)
Definition: SqlNumber.cs:213
SqlNumber Modulo(SqlNumber value)
Definition: SqlNumber.cs:571
SqlNumber(BigDecimal value)
Definition: SqlNumber.cs:39
SqlNumber Pow(SqlNumber exp)
Definition: SqlNumber.cs:677
void SetValue(string key, Type type, object value)
readonly BigDecimal innerValue
Definition: SqlNumber.cs:25
The number represents a positive infinity (for example, the result of a division of a positive number...
SqlNumber(NumericState state, BigDecimal value)
Definition: SqlNumber.cs:43
SqlNumber(double value, int precision)
Definition: SqlNumber.cs:92
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
SqlNumber SetScale(int scale, RoundingMode mode)
Definition: SqlNumber.cs:597
SqlNumber Round(int precision)
Definition: SqlNumber.cs:695
SqlNumber(byte[] bytes, int scale, int precision)
Definition: SqlNumber.cs:68
SqlNumber Divide(SqlNumber value)
Definition: SqlNumber.cs:554
SqlNumber Multiply(SqlNumber value)
Definition: SqlNumber.cs:539
SqlNumber And(SqlNumber value)
Definition: SqlNumber.cs:484
bool IsComparableTo(ISqlObject other)
Checks if the current object is comparable with the given one.
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
SqlNumber Subtract(SqlNumber value)
Definition: SqlNumber.cs:525
override bool Equals(object obj)
Definition: SqlNumber.cs:202
SqlNumber Or(SqlNumber value)
Definition: SqlNumber.cs:497
SqlNumber(int value, int precision)
Definition: SqlNumber.cs:72
int IComparable. CompareTo(object obj)
Definition: SqlNumber.cs:151
static SqlNumber Parse(string s)
Definition: SqlNumber.cs:738
SqlNumber(byte[] bytes, int scale)
Definition: SqlNumber.cs:64
Deveel.Data.Sql.Objects.SqlString SqlString
Definition: DataObject.cs:27
SqlNumber Add(SqlNumber value)
Definition: SqlNumber.cs:510