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


C# SqlDecimal.CalculatePrecision方法代码示例

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


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

示例1: OverflowException


//.........这里部分代码省略.........

            // When sign of first operand is negative
            // negate all operands including result.
            if (!fMySignPos)
            {
                fMySignPos = !fMySignPos;
                fOpSignPos = !fOpSignPos;
                fResSignPos = !fResSignPos;
            }

            // Initialize operand lengths and pointer.
            culOp1 = x.m_bLen;
            culOp2 = y.m_bLen;

            uint[] rglData1 = new uint[4] { x.m_data1, x.m_data2, x.m_data3, x.m_data4 };
            uint[] rglData2 = new uint[4] { y.m_data1, y.m_data2, y.m_data3, y.m_data4 };

            if (fOpSignPos)
            {
                dwlAccum = 0;

                // CONSIDER: Call AddUlong when possible

                // Loop through UI4s adding operands and putting result in *this
                // of the operands and put result in *this
                for (iulData = 0; iulData < culOp1 || iulData < culOp2; iulData++)
                {
                    // None of these DWORDLONG additions can overflow, as dwlAccum comes in < x_lInt32Base
                    if (iulData < culOp1)
                        dwlAccum += rglData1[iulData];
                    if (iulData < culOp2)
                        dwlAccum += rglData2[iulData];

                    rglData1[iulData] = (uint)dwlAccum; // equiv to mod x_lInt32Base
                    dwlAccum >>= 32; // equiv to div x_lInt32Base
                }

                //If carry
                if (dwlAccum != 0)
                {
                    Debug.Assert(dwlAccum < s_ulInt32Base);

                    //Either overflowed
                    if (iulData == s_cNumeMax)
                        throw new OverflowException(SQLResource.ArithOverflowMessage);

                    // Or extended length
                    rglData1[iulData] = (uint)dwlAccum;
                    iulData++;
                }

                // Set result length
                bLen = (byte)iulData;
            }
            else
            {
                int iulLastNonZero = 0; // The last nonzero UI

                // When second operand is negative, switch operands
                // if operand2 is greater than operand1
                if (x.LAbsCmp(y) < 0)
                {
                    fResSignPos = !fResSignPos;
                    uint[] rguiTemp = rglData2;
                    rglData2 = rglData1;
                    rglData1 = rguiTemp;
                    culOp1 = culOp2;
                    culOp2 = x.m_bLen;
                }

                dwlAccum = s_ulInt32Base;
                for (iulData = 0; iulData < culOp1 || iulData < culOp2; iulData++)
                {
                    if (iulData < culOp1)
                        dwlAccum += rglData1[iulData];
                    if (iulData < culOp2)
                        dwlAccum -= rglData2[iulData];

                    rglData1[iulData] = (uint)dwlAccum; // equiv to mod BaseUI4
                    if (rglData1[iulData] != 0)
                        iulLastNonZero = iulData;
                    dwlAccum >>= 32; // equiv to /= BaseUI4
                    dwlAccum += s_ulInt32BaseForMod; // equiv to BaseUI4 - 1
                }
                // Set length based on highest non-zero ULONG
                bLen = (byte)(iulLastNonZero + 1);
            }

            SqlDecimal ret = new SqlDecimal(rglData1, bLen, (byte)ResPrec, (byte)ResScale, fResSignPos);

            if (ret.FGt10_38() || ret.CalculatePrecision() > s_NUMERIC_MAX_PRECISION)
                throw new OverflowException(SQLResource.ArithOverflowMessage);

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

            ret.AssertValid();

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

示例2: while


//.........这里部分代码省略.........
     int num7 = y.m_bScale;
     int num9 = Math.Max((int) (x.m_bPrec - bScale), (int) (y.m_bPrec - num7));
     int num3 = Math.Max(bScale, num7);
     int num6 = (num9 + num3) + 1;
     num6 = Math.Min(MaxPrecision, num6);
     if ((num6 - num9) < num3)
     {
         num3 = num6 - num9;
     }
     if (bScale != num3)
     {
         x.AdjustScale(num3 - bScale, true);
     }
     if (num7 != num3)
     {
         y.AdjustScale(num3 - num7, true);
     }
     if (!isPositive)
     {
         isPositive = !isPositive;
         flag2 = !flag2;
         fPositive = !fPositive;
     }
     int bLen = x.m_bLen;
     int num4 = y.m_bLen;
     uint[] rglData = 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 };
     if (flag2)
     {
         num2 = 0L;
         num = 0;
         while ((num < bLen) || (num < num4))
         {
             if (num < bLen)
             {
                 num2 += rglData[num];
             }
             if (num < num4)
             {
                 num2 += numArray4[num];
             }
             rglData[num] = (uint) num2;
             num2 = num2 >> 0x20;
             num++;
         }
         if (num2 != 0L)
         {
             if (num == x_cNumeMax)
             {
                 throw new OverflowException(SQLResource.ArithOverflowMessage);
             }
             rglData[num] = (uint) num2;
             num++;
         }
         num11 = (byte) num;
     }
     else
     {
         int num10 = 0;
         if (x.LAbsCmp(y) < 0)
         {
             fPositive = !fPositive;
             uint[] numArray5 = numArray4;
             numArray4 = rglData;
             rglData = numArray5;
             bLen = num4;
             num4 = x.m_bLen;
         }
         num2 = x_ulInt32Base;
         for (num = 0; (num < bLen) || (num < num4); num++)
         {
             if (num < bLen)
             {
                 num2 += rglData[num];
             }
             if (num < num4)
             {
                 num2 -= numArray4[num];
             }
             rglData[num] = (uint) num2;
             if (rglData[num] != 0)
             {
                 num10 = num;
             }
             num2 = num2 >> 0x20;
             num2 += x_ulInt32BaseForMod;
         }
         num11 = (byte) (num10 + 1);
     }
     SqlDecimal num12 = new SqlDecimal(rglData, num11, (byte) num6, (byte) num3, fPositive);
     if (num12.FGt10_38() || (num12.CalculatePrecision() > NUMERIC_MAX_PRECISION))
     {
         throw new OverflowException(SQLResource.ArithOverflowMessage);
     }
     if (num12.FZero())
     {
         num12.SetPositive();
     }
     return num12;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:SqlDecimal.cs


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