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


C# UInt128.GetBitLength方法代码示例

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


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

示例1: TauSumInnerWorkerLarge

 private int TauSumInnerWorkerLarge(UInt128 y, ulong imin, ulong imax)
 {
     #if false
     var sum = (uint)0;
     for (var i = imin; i < imax; i++)
         sum ^= (uint)(y / i);
     return (int)(sum & 1);
     #endif
     #if false
     var yRep = (MutableInteger)y;
     var xRep = yRep.Copy();
     var iRep = (MutableInteger)imin;
     var store = new MutableIntegerStore(4);
     var sum = (uint)0;
     for (var i = imin; i < imax; i++)
     {
         sum ^= xRep.Set(yRep).Divide(iRep, store).LeastSignificantWord;
         iRep.Increment();
     }
     return (int)(sum & 1);
     #endif
     #if false
     // The quantity floor(y/d) is odd iff y mod 2d >= d.
     var sum = (ulong)0;
     for (var i = imin; i < imax; i++)
         sum ^= y % (i << 1) - i;
     sum >>= 63;
     if (((imax - imin) & 1) != 0)
         sum ^= 1;
     return (int)(sum & 1);
     #endif
     #if false
     if (y.IsPowerOfTwo)
     {
         var uBits = y.GetBitLength() - 32;
         var sum = (uint)0;
         var y0 = (UInt128)y.LeastSignificantWord;
         var y12 = (ulong)(y >> 32);
         for (var i = imin; i < imax; i++)
         {
             var y12mod = y12 % i;
             var yPrime = y0 + ((y12 % i) << 32);
             var shift = 64 - i.GetBitCount();
             sum ^= (uint)(y / i);
         }
         return (int)(sum & 1);
     }
     #endif
     #if false
     var sum = (uint)0;
     var i = imax - 1;
     var current = (ulong)(y / (i + 1));
     var delta = (ulong)(y / i - current);
     var mod = (long)(y - (UInt128)current * (i + 1));
     var imid = Math.Max(imin, (ulong)(y >> (64 - safetyBits)));
     while (i >= imid)
     {
         mod += (long)(current - delta * i);
         current += delta;
         if (mod >= (long)i)
         {
             ++delta;
             ++current;
             mod -= (long)i;
             if (mod >= (long)i)
                 break;
         }
         else if (mod < 0)
         {
             --delta;
             --current;
             mod += (long)i;
         }
         Debug.Assert(y / i == current);
         sum ^= (uint)current;
         --i;
     }
     while (i >= imin)
     {
         sum ^= (uint)(y / i);
         --i;
     }
     return (int)(sum & 1);
     #endif
     #if true
     var sum = (uint)0;
     var i = imax - 1;
     var current = (ulong)(y / (i + 1));
     var delta = (ulong)(y / i) - current;
     var mod = (long)(y - (UInt128)current * (i + 1));
     var imid = Math.Max(imin, (ulong)(y >> (64 - safetyBits)));
     var deltai = delta * (i + 1);
     while (i >= imid)
     {
         deltai -= delta;
         mod += (long)(current - deltai);
         if (mod >= (long)i)
         {
             ++delta;
             deltai += i;
//.........这里部分代码省略.........
开发者ID:ricksladkey,项目名称:Dirichlet,代码行数:101,代码来源:PrimeCounting.cs


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