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


C# NetBigInteger.QuickPow2Check方法代码示例

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


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

示例1: DivideAndRemainder

		public NetBigInteger[] DivideAndRemainder(
			NetBigInteger val)
		{
			if (val.m_sign == 0)
				throw new ArithmeticException("Division by zero error");

			NetBigInteger[] biggies = new NetBigInteger[2];

			if (m_sign == 0)
			{
				biggies[0] = Zero;
				biggies[1] = Zero;
			}
			else if (val.QuickPow2Check()) // val is power of two
			{
				int e = val.Abs().BitLength - 1;
				NetBigInteger quotient = Abs().ShiftRight(e);
				int[] remainder = LastNBits(e);

				biggies[0] = val.m_sign == m_sign ? quotient : quotient.Negate();
				biggies[1] = new NetBigInteger(m_sign, remainder, true);
			}
			else
			{
				int[] remainder = (int[])m_magnitude.Clone();
				int[] quotient = Divide(remainder, val.m_magnitude);

				biggies[0] = new NetBigInteger(m_sign * val.m_sign, quotient, true);
				biggies[1] = new NetBigInteger(m_sign, remainder, true);
			}

			return biggies;
		}
开发者ID:BenMatase,项目名称:RaginRovers,代码行数:33,代码来源:NetBigInteger.cs

示例2: Remainder

		public NetBigInteger Remainder(
			NetBigInteger n)
		{
			if (n.m_sign == 0)
				throw new ArithmeticException("Division by zero error");

			if (m_sign == 0)
				return Zero;

			// For small values, use fast remainder method
			if (n.m_magnitude.Length == 1)
			{
				int val = n.m_magnitude[0];

				if (val > 0)
				{
					if (val == 1)
						return Zero;

					int rem = Remainder(val);

					return rem == 0
						? Zero
						: new NetBigInteger(m_sign, new int[] { rem }, false);
				}
			}

			if (CompareNoLeadingZeroes(0, m_magnitude, 0, n.m_magnitude) < 0)
				return this;

			int[] result;
			if (n.QuickPow2Check())  // n is power of two
			{
				result = LastNBits(n.Abs().BitLength - 1);
			}
			else
			{
				result = (int[])m_magnitude.Clone();
				result = Remainder(result, n.m_magnitude);
			}

			return new NetBigInteger(m_sign, result, true);
		}
开发者ID:BenMatase,项目名称:RaginRovers,代码行数:43,代码来源:NetBigInteger.cs

示例3: Divide

		public NetBigInteger Divide(
			NetBigInteger val)
		{
			if (val.m_sign == 0)
				throw new ArithmeticException("Division by zero error");

			if (m_sign == 0)
				return Zero;

			if (val.QuickPow2Check()) // val is power of two
			{
				NetBigInteger result = Abs().ShiftRight(val.Abs().BitLength - 1);
				return val.m_sign == m_sign ? result : result.Negate();
			}

			int[] mag = (int[])m_magnitude.Clone();

			return new NetBigInteger(m_sign * val.m_sign, Divide(mag, val.m_magnitude), true);
		}
开发者ID:BenMatase,项目名称:RaginRovers,代码行数:19,代码来源:NetBigInteger.cs

示例4: Multiply

		public NetBigInteger Multiply(
			NetBigInteger val)
		{
			if (m_sign == 0 || val.m_sign == 0)
				return Zero;

			if (val.QuickPow2Check()) // val is power of two
			{
				NetBigInteger result = ShiftLeft(val.Abs().BitLength - 1);
				return val.m_sign > 0 ? result : result.Negate();
			}

			if (QuickPow2Check()) // this is power of two
			{
				NetBigInteger result = val.ShiftLeft(Abs().BitLength - 1);
				return m_sign > 0 ? result : result.Negate();
			}

			int maxBitLength = BitLength + val.BitLength;
			int resLength = (maxBitLength + BitsPerInt - 1) / BitsPerInt;

			int[] res = new int[resLength];

			if (val == this)
			{
				Square(res, m_magnitude);
			}
			else
			{
				Multiply(res, m_magnitude, val.m_magnitude);
			}

			return new NetBigInteger(m_sign * val.m_sign, res, true);
		}
开发者ID:BenMatase,项目名称:RaginRovers,代码行数:34,代码来源:NetBigInteger.cs


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