當前位置: 首頁>>代碼示例>>C#>>正文


C# Number.CompareTo方法代碼示例

本文整理匯總了C#中System.Number.CompareTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Number.CompareTo方法的具體用法?C# Number.CompareTo怎麽用?C# Number.CompareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Number的用法示例。


在下文中一共展示了Number.CompareTo方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Subtract

        public override Number Subtract (Number x, Number y)
        {
            if (x.data.Length < 6 || y.data.Length < 6)
                return ToElement (base.Subtract (x, y));

            int cmp = x.CompareTo (y);
            if (cmp == 0)
                return PADDED_ZERO;
            uint[] pz = new uint[6], px = x.data, py = y.data;
            if (cmp > 0) {
                uint tmp, carry;
                tmp = py[0]; carry = ((pz[0] = px[0] - tmp) > ~tmp ? 1U : 0U);
                tmp = py[1] + carry; carry = (tmp < carry | (pz[1] = px[1] - tmp) > ~tmp ? 1U : 0U);
                tmp = py[2] + carry; carry = (tmp < carry | (pz[2] = px[2] - tmp) > ~tmp ? 1U : 0U);
                tmp = py[3] + carry; carry = (tmp < carry | (pz[3] = px[3] - tmp) > ~tmp ? 1U : 0U);
                tmp = py[4] + carry; carry = (tmp < carry | (pz[4] = px[4] - tmp) > ~tmp ? 1U : 0U);
                pz[5] = px[5] - py[5] - carry;
            } else {
                long tmp;
                int carry = 0;
                pz[0] = (uint)(tmp = ((long)px[0]) + ((long)P1) - ((long)py[0]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0);
                pz[1] = (uint)(tmp = ((long)px[1]) + ((long)P2) - ((long)py[1]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0);
                pz[2] = (uint)(tmp = ((long)px[2]) + ((long)P3) - ((long)py[2]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0);
                pz[3] = (uint)(tmp = ((long)px[3]) + ((long)P4) - ((long)py[3]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0);
                pz[4] = (uint)(tmp = ((long)px[4]) + ((long)P5) - ((long)py[4]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0);
                pz[5] = (uint)(tmp = ((long)px[5]) + ((long)P6) - ((long)py[5]) - carry);
            }
            return new Number (pz);
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:29,代碼來源:SECP192r1.cs

示例2: ECGroup

        public ECGroup (Number a, Number b, Number mod, IFiniteField field)
        {
            _a = a;
            _b = b;
            _mod = mod;
            _field = field;
            _a_is_minus3 = (mod.CompareTo (a + Number.Three) == 0);
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:8,代碼來源:ECGroup.cs

示例3: Multiply


//.........這裏部分代碼省略.........
            r0 += tmp1 + tmp2 - tmp4 - tmp5 - tmp32;

            tmp = ((ulong)px[0]) * ((ulong)py[6]); r6 += tmp & mask; r7 += tmp >> 32;
            tmp = ((ulong)px[1]) * ((ulong)py[6]); r7 += tmp & mask; tmp1 = (uint)(tmp >> 32);
            tmp = ((ulong)px[2]) * ((ulong)py[6]); tmp1 += (uint)tmp; tmp2 = (uint)(tmp >> 32);
            tmp = ((ulong)px[3]) * ((ulong)py[6]); tmp2 += (uint)tmp; tmp3 = (uint)(tmp >> 32);
            tmp = ((ulong)px[4]) * ((ulong)py[6]); tmp3 += (uint)tmp; tmp4 = (uint)(tmp >> 32);
            tmp = ((ulong)px[5]) * ((ulong)py[6]); tmp4 += (uint)tmp; tmp5 = (uint)(tmp >> 32);
            tmp = ((ulong)px[6]) * ((ulong)py[6]); tmp5 += (uint)tmp; tmp6 = (uint)(tmp >> 32);
            tmp = ((ulong)px[7]) * ((ulong)py[6]); tmp6 += (uint)tmp; tmp32 = (uint)(tmp >> 32);
            d1 = tmp4 << 1;
            d2 = tmp5 << 1;
            d3 = tmp6 << 1;
            d4 = ((ulong)tmp32) << 1;
            triple1 = d4 + tmp32;
            r7 += tmp1 - tmp3 - tmp4 - tmp5 - tmp6;
            r6 -= tmp1 + tmp2 - tmp6 - triple1;
            r5 -= tmp3 + tmp4 - d3 - d4;
            r4 -= tmp2 + tmp3 - d2 - d3 - tmp32;
            r3 -= tmp1 + tmp2 - d1 - d2 - tmp6;
            r2 += tmp3 + tmp4 - tmp6 - tmp32;
            r1 += tmp2 + tmp3 - tmp5 - tmp6 - tmp32;
            r0 += tmp1 + tmp2 - tmp4 - tmp5 - tmp6 - tmp32;

            tmp = ((ulong)px[0]) * ((ulong)py[7]); r7 += tmp & mask; tmp1 = (uint)(tmp >> 32);
            tmp = ((ulong)px[1]) * ((ulong)py[7]); tmp1 += (uint)tmp; tmp2 = (uint)(tmp >> 32);
            tmp = ((ulong)px[2]) * ((ulong)py[7]); tmp2 += (uint)tmp; tmp3 = (uint)(tmp >> 32);
            tmp = ((ulong)px[3]) * ((ulong)py[7]); tmp3 += (uint)tmp; tmp4 = (uint)(tmp >> 32);
            tmp = ((ulong)px[4]) * ((ulong)py[7]); tmp4 += (uint)tmp; tmp5 = (uint)(tmp >> 32);
            tmp = ((ulong)px[5]) * ((ulong)py[7]); tmp5 += (uint)tmp; tmp6 = (uint)(tmp >> 32);
            tmp = ((ulong)px[6]) * ((ulong)py[7]); tmp6 += (uint)tmp; tmp7 = (uint)(tmp >> 32);
            tmp = ((ulong)px[7]) * ((ulong)py[7]); tmp7 += (uint)tmp; tmp32 = (uint)(tmp >> 32);
            d1 = tmp4 << 1;
            d2 = tmp5 << 1;
            d3 = tmp6 << 1;
            d4 = tmp7 << 1;
            d5 = ((ulong)tmp32) << 1;
            triple1 = d4 + tmp7;
            triple2 = d5 + tmp32;
            r7 += tmp1 - tmp3 - tmp4 - tmp5 - tmp6 + triple2;
            r6 -= tmp1 + tmp2 - tmp6 - triple1 - d5;
            r5 -= tmp3 + tmp4 - d3 - d4 - tmp32;
            r4 -= tmp2 + tmp3 - d2 - d3 - tmp7;
            r3 -= tmp1 + tmp2 - d1 - d2 - tmp6 + tmp32;
            r2 += tmp3 + tmp4 - tmp6 - tmp7 - tmp32;
            r1 += tmp2 + tmp3 - tmp5 - tmp6 - tmp7 - tmp32;
            r0 += tmp1 + tmp2 - tmp4 - tmp5 - tmp6 - tmp7;

            // check negative-value
            while (r0 >= negative) { r1--; r0 += carry; }
            while (r1 >= negative) { r2--; r1 += carry; }
            while (r2 >= negative) { r3--; r2 += carry; }
            while (r3 >= negative) { r4--; r3 += carry; }
            while (r4 >= negative) { r5--; r4 += carry; }
            while (r5 >= negative) { r6--; r5 += carry; }
            while (r6 >= negative) { r7--; r6 += carry; }
            while (r7 >= negative) {
                r0 += P1;
                r1 += P2;
                r2 += P3;
                r3 += P4;
                r4 += P5;
                r5 += P6;
                r6 += P7;
                r7 += P8;
            }

            // check carry
            while (r0 > mask || r1 > mask || r2 > mask || r3 > mask || r4 > mask || r5 > mask || r6 > mask || r7 > mask) {
                if (r7 > mask) {
                    tmp32 = (uint)(r7 >> 32);
                    r0 += tmp32;
                    r3 -= tmp32;
                    r6 -= tmp32;
                    r7 = tmp32 + (ulong)((uint)r7);

                    // check negative-value
                    while (r3 >= negative) { r4--; r3 += carry; }
                    while (r4 >= negative) { r5--; r4 += carry; }
                    while (r5 >= negative) { r6--; r5 += carry; }
                    while (r6 >= negative) { r7--; r6 += carry; }
                }
                tmp32 = (uint)(r0 >> 32); r0 = (uint)r0; r1 += tmp32;
                tmp32 = (uint)(r1 >> 32); r1 = (uint)r1; r2 += tmp32;
                tmp32 = (uint)(r2 >> 32); r2 = (uint)r2; r3 += tmp32;
                tmp32 = (uint)(r3 >> 32); r3 = (uint)r3; r4 += tmp32;
                tmp32 = (uint)(r4 >> 32); r4 = (uint)r4; r5 += tmp32;
                tmp32 = (uint)(r5 >> 32); r5 = (uint)r5; r6 += tmp32;
                tmp32 = (uint)(r6 >> 32); r6 = (uint)r6; r7 += tmp32;
            }

            Number ret = new Number (new uint[] {
                (uint)r0, (uint)r1, (uint)r2,
                (uint)r3, (uint)r4, (uint)r5,
                (uint)r6, (uint)r7
            });
            while (ret.CompareTo (PRIME) >= 0)
                ret.SubtractInPlace (PRIME);
            return ret;
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:101,代碼來源:SECP256r1.cs

示例4: Reduce

        public unsafe void Reduce (Number x)
        {
            int k = mod.length, kp1 = k + 1, km1 = k - 1;

            if (x.length < k)
                return;

            Number q = new Number (x.length - km1 + constant.length);
            Number r = new Number (kp1);
            fixed (uint* pq = q.data, pr = r.data, pm = mod.data, px = x.data, pc = constant.data) {
                Number.Multiply (px + km1, x.length - km1, pc, constant.length, pq);

                x.length = (x.length > kp1 ? kp1 : x.length);
                x.Normalize ();

                uint* xs = pq + kp1, xe = xs + q.length - kp1;
                uint* ys = pm, ye = ys + mod.length;
                uint* zs = pr, ze = zs + kp1;

                for (; xs < xe; xs++, zs++) {
                    if (*xs == 0) continue;
                    ulong carry = 0;
                    uint* zp = zs;
                    for (uint* yp = ys; yp < ye && zp < ze; yp++, zp++) {
                        carry += ((ulong)*xs) * ((ulong)*yp) + ((ulong)*zp);
                        *zp = (uint)carry;
                        carry >>= 32;
                    }
                    if (carry != 0 && zp < ze)
                        *zp = (uint)carry;
                }
                r.Normalize ();

                if (r.CompareTo (x) <= 0) {
                    x.length = Number.Subtract (px, x.length, pr, r.length, px);
                } else {
                    Number val = new Number (kp1 + 1);
                    val.data[kp1] = 1;
                    fixed (uint* pv = val.data) {
                        val.length = Number.Subtract (pv, val.length, pr, r.length, pv);
                        x.length = Number.Add (px, x.length, pv, val.length, px);
                    }
                }
                x.Normalize ();

                while (x.CompareTo (mod) >= 0) {
                    x.length = Number.Subtract (px, x.length, pm, mod.length, px);
                }
            }
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:50,代碼來源:Barrett.cs

示例5: LeftSmallerThanRight

 public static bool LeftSmallerThanRight(Number num1, Number num2)
 {
     return num1.CompareTo(num2) < 0;
 }
開發者ID:suparna619,項目名稱:Spikes,代碼行數:4,代碼來源:Program.cs

示例6: Sqrt

        public virtual Number Sqrt (Number x)
        {
            if ((mod % (uint)4) == 3) {
                Number tmp = Pow (x, (mod >> 2) + 1);
                if (x.CompareTo (Multiply (tmp, tmp)) == 0)
                    return tmp;
                throw new ArithmeticException ();
            }
            throw new NotImplementedException ();
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:10,代碼來源:Classical.cs

示例7: ExportECPoint

        public override ECPoint ExportECPoint (Number x, Number y, Number z, ECGroup group)
        {
            if (montOne == null) montOne = ToElement (Number.One);
            if (z.CompareTo (montOne) == 0)
                return new ECPoint (group, Multiply (x, Number.One), Multiply (y, Number.One), Number.One);

            Number izm = Invert (z);
            Number iz = Multiply (izm, Number.One);
            Number z2 = Multiply (iz, izm);
            return new ECPoint (group, Multiply (x, z2), Multiply (y, (Multiply (z2, izm))), Number.One);
        }
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:11,代碼來源:Montgomery.cs


注:本文中的System.Number.CompareTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。