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


C# Number.IsZero方法代码示例

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


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

示例1: Pow

		public virtual Number Pow (Number x, Number y)
		{
			if (y.IsZero ())
				return ToElement (Number.One);
			if (y.IsOne ())
				return x;

			Number a = x;
			Number b = ToElement (Number.One);
			if (y.GetBit (0) == 1)
				b = a;
			for (int i = 1; i < y.BitCount (); i ++) {
				a = Multiply (a, a);
				if (y.GetBit (i) == 1)
					b = Multiply (a, b);
			}
			return b;
		}
开发者ID:kazuki,项目名称:opencrypto.net,代码行数:18,代码来源:Classical.cs

示例2: Multiply

		public override unsafe Number Multiply (Number x, Number y)
		{
			if (x.IsZero () || y.IsZero ())
				return Number.Zero;
			if (x.length < y.length) {
				Number swap = x;
				x = y;
				y = swap;
			}
			uint[] z = new uint[mod.length + 1];
			fixed (uint* px = x.data, py = y.data, pz = z, pp = mod.data) {
				uint y0 = py[0];
				int i = 0;
				for (; i < x.length; i++) {
					uint u = (uint)((pz[0] + px[i] * y0) * invMod);
					uint xi = px[i];
					ulong carry1 = ((ulong)xi) * ((ulong)py[0]);
					ulong carry2 = ((ulong)u) * ((ulong)pp[0]);
					ulong carry = (((ulong)(uint)carry1) + ((ulong)(uint)carry2) + ((ulong)pz[0])) >> 32;
					carry1 >>= 32; carry2 >>= 32;
					int k = 1;
					for (; k < y.length; k++) {
						carry1 += ((ulong)xi) * ((ulong)py[k]);
						carry2 += ((ulong)u) * ((ulong)pp[k]);
						carry += ((ulong)(uint)carry1) + ((ulong)(uint)carry2) + ((ulong)pz[k]);
						pz[k - 1] = (uint)carry;
						carry >>= 32; carry1 >>= 32; carry2 >>= 32;
					}
					for (; carry1 != 0 && k < mod.length; k++) {
						carry2 += ((ulong)u) * ((ulong)pp[k]);
						carry += ((ulong)(uint)carry1) + ((ulong)(uint)carry2) + ((ulong)pz[k]);
						pz[k - 1] = (uint)carry;
						carry >>= 32; carry1 >>= 32; carry2 >>= 32;
					}
					for (; k < mod.length; k++) {
						carry2 += ((ulong)u) * ((ulong)pp[k]);
						carry += ((ulong)(uint)carry2) + ((ulong)pz[k]);
						pz[k - 1] = (uint)carry;
						carry >>= 32; carry2 >>= 32;
					}
					carry += carry1 + carry2 + ((ulong)pz[k]);
					pz[k - 1] = (uint)carry;
					pz[k] = (uint)(carry >> 32);
				}
				for (; i < mod.length; i++) {
					uint u = (uint)(pz[0] * invMod);
					ulong carry = (((ulong)u) * ((ulong)pp[0]) + ((ulong)pz[0])) >> 32;
					int k = 1;
					for (; k < mod.length; k++) {
						carry += ((ulong)u) * ((ulong)pp[k]) + ((ulong)pz[k]);
						pz[k - 1] = (uint)carry;
						carry >>= 32;
					}
					carry += ((ulong)pz[k]);
					pz[k - 1] = (uint)carry;
					pz[k] = (uint)(carry >> 32);
				}
				if (pz[mod.length] != 0 || Number.Compare (z, mod.length, mod.data, mod.length) >= 0)
					return new Number (z, Number.Subtract (pz, z.Length, pp, mod.length, pz));
				return new Number (z);
			}
		}
开发者ID:kazuki,项目名称:opencrypto.net,代码行数:62,代码来源:Montgomery.cs


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