当前位置: 首页>>代码示例>>C#>>正文


C# SqlDecimal.AddULong方法代码示例

本文整理汇总了C#中System.Data.SqlTypes.SqlDecimal.AddULong方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDecimal.AddULong方法的具体用法?C# SqlDecimal.AddULong怎么用?C# SqlDecimal.AddULong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlTypes.SqlDecimal的用法示例。


在下文中一共展示了SqlDecimal.AddULong方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Round

        private static SqlDecimal Round(SqlDecimal n, int lPosition, bool fTruncate)
        {
            if (n.IsNull)
                return SqlDecimal.Null;

            if (lPosition >= 0)
            {
                //If round to the right of decimal number
                lPosition = Math.Min(s_NUMERIC_MAX_PRECISION, lPosition);
                if (lPosition >= n.m_bScale)
                    return n;   //No need to round
            }
            else
            {
                //If round to the left of the decimal point
                lPosition = Math.Max(-s_NUMERIC_MAX_PRECISION, lPosition);

                //Return +0.00 if truncation of integer part
                if (lPosition < n.m_bScale - n.m_bPrec)
                {
                    n.SetToZero();
                    return n;
                }
            }

            uint ulRem = 0;                                         // Remainder: the highest significant digit to be truncated
            int lAdjust = Math.Abs(lPosition - (int)n.m_bScale);    // Precision adjustment
            uint ulLastDivBase = 1;                                 //

            //Compute the integral part of the numeric
            while (lAdjust > 0)
            {
                if (lAdjust >= 9)
                {
                    ulRem = n.DivByULong(s_rgulShiftBase[8]);
                    ulLastDivBase = s_rgulShiftBase[8];
                    lAdjust -= 9;
                }
                else
                {
                    ulRem = n.DivByULong(s_rgulShiftBase[lAdjust - 1]);
                    ulLastDivBase = s_rgulShiftBase[lAdjust - 1];
                    lAdjust = 0;
                }
            }

            // The rounding only depends on the first digit after the rounding position
            if (ulLastDivBase > 1)
            {
                ulRem /= (ulLastDivBase / 10);
            }

            //If result is zero, return
            if (n.FZero() && (fTruncate || ulRem < 5))
            {
                n.SetPositive();
                n.AssertValid();
                return n;
            }

            // Adjust by adding 1 if remainder is larger than 5
            if (ulRem >= 5 && !fTruncate)
                n.AddULong(1);

            // Convert back to original scale
            lAdjust = Math.Abs(lPosition - n.m_bScale);

            while (lAdjust-- > 0)
            {
                n.MultByULong(s_ulBase10);
            }

            n.AssertValid();
            return n;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:75,代码来源:SQLDecimal.cs

示例2: Floor

        // Floor - next largest integer smaller or equal to the numeric
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static SqlDecimal Floor(SqlDecimal n)
        {
            n.AssertValid();

            if (n.IsNull)
                return SqlDecimal.Null;

            if (n.m_bScale == 0)
                return n;

            bool fFraction;    //Fractional flag

            n.MakeInteger(out fFraction);

            //When the numeric has fraction and is negative, subtract 1 by calling AddULong(1)
            //Otherwise return the integral part.
            if (fFraction && !n.IsPositive)
            {
                n.AddULong(1);
            }

            if (n.FZero())//if result is zero, sign should be positive
                n.SetPositive();
            n.AssertValid();
            return n;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:30,代码来源:SQLDecimal.cs

示例3: result


//.........这里部分代码省略.........
            // Calculate actual result length
            culRes = idRes + 1;

            // III) Adjust precision,scale to result prec,scale
            if (lScaleAdjust != 0)
            {
                // If need to decrease scale
                if (lScaleAdjust < 0)
                {
                    Debug.Assert(s_NUMERIC_MAX_PRECISION == ResPrec);

                    // have to adjust - might yet end up fitting.
                    // Cannot call AdjustScale - number cannot fit in a numeric, so
                    // have to duplicate code here

                    uint ulRem;          //Remainder when downshifting
                    uint ulShiftBase;    //What to multiply by to effect scale adjust

                    do
                    {
                        if (lScaleAdjust <= -9)
                        {
                            ulShiftBase = s_rgulShiftBase[8];
                            lScaleAdjust += 9;
                        }
                        else
                        {
                            ulShiftBase = s_rgulShiftBase[-lScaleAdjust - 1];
                            lScaleAdjust = 0;
                        }
                        MpDiv1(rgulRes, ref culRes, ulShiftBase, out ulRem);
                    }
                    while (lScaleAdjust != 0);

                    // Still do not fit?
                    if (culRes > s_cNumeMax)
                        throw new OverflowException(SQLResource.ArithOverflowMessage);

                    for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                        rgulRes[idRes] = 0;
                    ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ResScale, fResPositive);

                    // Is it greater than 10**38?
                    if (ret.FGt10_38())
                        throw new OverflowException(SQLResource.ArithOverflowMessage);

                    ret.AssertValid();

                    // If remainder is 5 or above, increment/decrement by 1.
                    if (ulRem >= ulShiftBase / 2)
                        ret.AddULong(1);
                    // After adjusting, if the result is 0 and remainder is less than 5,
                    // set the sign to be positive
                    if (ret.FZero())
                        ret.SetPositive();

                    return ret;
                }

                // Otherwise call AdjustScale
                if (culRes > s_cNumeMax)    // Do not fit now, so will not fit after adjustment
                    throw new OverflowException(SQLResource.ArithOverflowMessage);
                // NOTE: Have not check for value in the range (10**38..2**128),
                // as we'll call AdjustScale with positive argument, and it'll
                // return "normal" overflow

                for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                    rgulRes[idRes] = 0;
                ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ActualScale, fResPositive);

                if (ret.FZero())
                    ret.SetPositive();

                ret.AssertValid();

                ret.AdjustScale(lScaleAdjust, true);

                return ret;
            }
            else
            {
                if (culRes > s_cNumeMax)
                    throw new OverflowException(SQLResource.ArithOverflowMessage);

                for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                    rgulRes[idRes] = 0;
                ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ResScale, fResPositive);

                // Is it greater than 10**38?
                if (ret.FGt10_38())
                    throw new OverflowException(SQLResource.ArithOverflowMessage);

                if (ret.FZero())
                    ret.SetPositive();

                ret.AssertValid();

                return ret;
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:101,代码来源:SQLDecimal.cs

示例4: while

 public static SqlDecimal operator *(SqlDecimal x, SqlDecimal y)
 {
     SqlDecimal num11;
     if (x.IsNull || y.IsNull)
     {
         return Null;
     }
     int bLen = y.m_bLen;
     int num10 = x.m_bScale + y.m_bScale;
     int num3 = num10;
     int num13 = ((x.m_bPrec - x.m_bScale) + (y.m_bPrec - y.m_bScale)) + 1;
     int num6 = num3 + num13;
     if (num6 > NUMERIC_MAX_PRECISION)
     {
         num6 = NUMERIC_MAX_PRECISION;
     }
     if (num3 > NUMERIC_MAX_PRECISION)
     {
         num3 = NUMERIC_MAX_PRECISION;
     }
     num3 = Math.Max(Math.Min(num6 - num13, num3), Math.Min(num10, x_cNumeDivScaleMin));
     int digits = num3 - num10;
     bool fPositive = x.IsPositive == y.IsPositive;
     uint[] numArray5 = new uint[] { x.m_data1, x.m_data2, x.m_data3, x.m_data4 };
     uint[] numArray4 = new uint[] { y.m_data1, y.m_data2, y.m_data3, y.m_data4 };
     uint[] rgulU = new uint[9];
     int index = 0;
     for (int i = 0; i < x.m_bLen; i++)
     {
         uint num16 = numArray5[i];
         ulong num2 = 0L;
         index = i;
         for (int j = 0; j < bLen; j++)
         {
             ulong num7 = num2 + rgulU[index];
             ulong num15 = numArray4[j];
             num2 = num16 * num15;
             num2 += num7;
             if (num2 < num7)
             {
                 num7 = x_ulInt32Base;
             }
             else
             {
                 num7 = 0L;
             }
             rgulU[index++] = (uint) num2;
             num2 = (num2 >> 0x20) + num7;
         }
         if (num2 != 0L)
         {
             rgulU[index++] = (uint) num2;
         }
     }
     while ((rgulU[index] == 0) && (index > 0))
     {
         index--;
     }
     int ciulU = index + 1;
     if (digits != 0)
     {
         if (digits < 0)
         {
             uint num12;
             uint num14;
             do
             {
                 if (digits <= -9)
                 {
                     num12 = x_rgulShiftBase[8];
                     digits += 9;
                 }
                 else
                 {
                     num12 = x_rgulShiftBase[-digits - 1];
                     digits = 0;
                 }
                 MpDiv1(rgulU, ref ciulU, num12, out num14);
             }
             while (digits != 0);
             if (ciulU > x_cNumeMax)
             {
                 throw new OverflowException(SQLResource.ArithOverflowMessage);
             }
             for (index = ciulU; index < x_cNumeMax; index++)
             {
                 rgulU[index] = 0;
             }
             num11 = new SqlDecimal(rgulU, (byte) ciulU, (byte) num6, (byte) num3, fPositive);
             if (num11.FGt10_38())
             {
                 throw new OverflowException(SQLResource.ArithOverflowMessage);
             }
             if (num14 >= (num12 / 2))
             {
                 num11.AddULong(1);
             }
             if (num11.FZero())
             {
                 num11.SetPositive();
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:SqlDecimal.cs

示例5: Round

 private static SqlDecimal Round(SqlDecimal n, int lPosition, bool fTruncate)
 {
     if (n.IsNull)
     {
         return Null;
     }
     if (lPosition >= 0)
     {
         lPosition = Math.Min(NUMERIC_MAX_PRECISION, lPosition);
         if (lPosition >= n.m_bScale)
         {
             return n;
         }
     }
     else
     {
         lPosition = Math.Max(-NUMERIC_MAX_PRECISION, lPosition);
         if (lPosition < (n.m_bScale - n.m_bPrec))
         {
             n.SetToZero();
             return n;
         }
     }
     uint num2 = 0;
     int num = Math.Abs((int) (lPosition - n.m_bScale));
     uint num3 = 1;
     while (num > 0)
     {
         if (num >= 9)
         {
             num2 = n.DivByULong(x_rgulShiftBase[8]);
             num3 = x_rgulShiftBase[8];
             num -= 9;
         }
         else
         {
             num2 = n.DivByULong(x_rgulShiftBase[num - 1]);
             num3 = x_rgulShiftBase[num - 1];
             num = 0;
         }
     }
     if (num3 > 1)
     {
         num2 /= num3 / 10;
     }
     if (n.FZero() && (fTruncate || (num2 < 5)))
     {
         n.SetPositive();
         return n;
     }
     if ((num2 >= 5) && !fTruncate)
     {
         n.AddULong(1);
     }
     num = Math.Abs((int) (lPosition - n.m_bScale));
     while (num-- > 0)
     {
         n.MultByULong(x_ulBase10);
     }
     return n;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:61,代码来源:SqlDecimal.cs

示例6: Floor

 public static SqlDecimal Floor(SqlDecimal n)
 {
     if (n.IsNull)
     {
         return Null;
     }
     if (n.m_bScale != 0)
     {
         bool flag;
         n.MakeInteger(out flag);
         if (flag && !n.IsPositive)
         {
             n.AddULong(1);
         }
         if (n.FZero())
         {
             n.SetPositive();
         }
     }
     return n;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:SqlDecimal.cs


注:本文中的System.Data.SqlTypes.SqlDecimal.AddULong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。