Пример #1
0
        public static TdsBoolean operator <=(TdsDecimal x, TdsDecimal y)
        {
            if (x.IsNull || y.IsNull)
            {
                return(TdsBoolean.Null);
            }

            if (x.Scale > y.Scale)
            {
                x = TdsDecimal.AdjustScale(x, y.Scale - x.Scale, true);
            }
            else if (y.Scale > x.Scale)
            {
                y = TdsDecimal.AdjustScale(y, x.Scale - y.Scale, true);
            }

            for (int i = 3; i >= 0; i -= 1)
            {
                if (x.Data[i] == 0 && y.Data[i] == 0)
                {
                    continue;
                }
                else
                {
                    return(new TdsBoolean(x.Data[i] <= y.Data[i]));
                }
            }
            return(new TdsBoolean(true));
        }
Пример #2
0
        public static TdsBoolean operator !=(TdsDecimal x, TdsDecimal y)
        {
            if (x.IsNull || y.IsNull)
            {
                return(TdsBoolean.Null);
            }

            if (x.Scale > y.Scale)
            {
                x = TdsDecimal.AdjustScale(x, y.Scale - x.Scale, true);
            }
            else if (y.Scale > x.Scale)
            {
                y = TdsDecimal.AdjustScale(y, x.Scale - y.Scale, true);
            }

            for (int i = 0; i < 4; i += 1)
            {
                if (x.Data[i] != y.Data[i])
                {
                    return(new TdsBoolean(true));
                }
            }
            return(new TdsBoolean(false));
        }
Пример #3
0
        public static TdsDecimal operator *(TdsDecimal x, TdsDecimal y)
        {
            // adjust the scale to the smaller of the two beforehand
            if (x.Scale > y.Scale)
            {
                x = TdsDecimal.AdjustScale(x, y.Scale - x.Scale, true);
            }
            else if (y.Scale > x.Scale)
            {
                y = TdsDecimal.AdjustScale(y, x.Scale - y.Scale, true);
            }

            // set the precision to the greater of the two
            byte resultPrecision;

            if (x.Precision > y.Precision)
            {
                resultPrecision = x.Precision;
            }
            else
            {
                resultPrecision = y.Precision;
            }

            int[] xData      = x.Data;
            int[] yData      = y.Data;
            int[] resultBits = new int[4];

            ulong res;
            ulong carry = 0;

            // multiply one at a time, and carry the results over to the next
            for (int i = 0; i < 4; i += 1)
            {
                carry = 0;
                res   = (ulong)(xData[i]) * (ulong)(yData[i]) + carry;
                if (res > Int32.MaxValue)
                {
                    carry = res - Int32.MaxValue;
                    res   = Int32.MaxValue;
                }
                resultBits [i] = (int)res;
            }

            // if we have carry left, then throw an exception
            if (carry > 0)
            {
                throw new OverflowException();
            }
            else
            {
                return(new TdsDecimal(resultPrecision, x.Scale, (x.IsPositive == y.IsPositive), resultBits));
            }
        }