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


C# HugeInt.SetTo方法代码示例

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


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

示例1: IntAssignRational

 public void IntAssignRational()
 {
     using (var a = new HugeRational("222509832503450298345029835740293845720/7"))
     using (var b = new HugeInt())
     {
         b.SetTo(a);
         Assert.AreEqual("31787118929064328335004262248613406531", b.ToString());
     }
 }
开发者ID:romance-ii,项目名称:mpir,代码行数:9,代码来源:Assignment.cs

示例2: IntFitsShort

 public void IntFitsShort()
 {
     using (var a = new HugeInt(short.MaxValue))
     {
         Assert.IsTrue(a.FitsShort());
         a.Value = a + 1;
         Assert.IsFalse(a.FitsShort());
         a.SetTo(short.MinValue);
         Assert.IsTrue(a.FitsShort());
         a.Value = a - 1;
         Assert.IsFalse(a.FitsShort());
     }
 }
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Conversions.cs

示例3: IntImportExport

        public void IntImportExport()
        {
            using (var a = new HugeInt("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"))
            using (var b = new HugeInt())
            {
                var bytes = new byte[1000];

                foreach (var order in Enum.GetValues(typeof(LimbOrder)).Cast<LimbOrder>())
                foreach (var endianness in Enum.GetValues(typeof(Endianness)).Cast<Endianness>())
                foreach (var nails in new[] { 0, 5, 10, 16 })
                foreach (var size in new[] { 8, 11, 16 })
                {
                    var words = a.Export(bytes, size, order, endianness, nails);
                    var expected = (ulong)System.Math.Ceiling(193m / (size * 8 - nails));
                    Assert.AreEqual(expected, words);

                    b.SetTo(0);
                    b.Import(bytes, words, size, order, endianness, nails);
                    Assert.AreEqual(a, b);
                }
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:22,代码来源:IO.cs

示例4: IntImportExportAllocating

        public void IntImportExportAllocating()
        {
            using (var a = new HugeInt("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"))
            using (var b = new HugeInt())
            {
                foreach (var order in Enum.GetValues(typeof(LimbOrder)).Cast<LimbOrder>())
                    foreach (var endianness in Enum.GetValues(typeof(Endianness)).Cast<Endianness>())
                        foreach (var nails in new[] { 0, 5, 10, 16 })
                            foreach (var size in new[] { 8, 11, 16 })
                            {
                                var bytes = a.Export<byte>(size, order, endianness, nails);
                                var expected = (int)System.Math.Ceiling(193m / (size * 8 - nails));
                                Assert.AreEqual(expected, bytes.Length / size);

                                b.SetTo(0);
                                b.Import(bytes, (uint)(bytes.Length / size), size, order, endianness, nails);
                                Assert.AreEqual(a, b);
                            }
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:20,代码来源:IO.cs

示例5: IntImportExportAllocatingZero

        public void IntImportExportAllocatingZero()
        {
            using (var a = new HugeInt())
            using (var b = new HugeInt())
            {
                var order = LimbOrder.LeastSignificantFirst;
                var endianness = Endianness.Native;
                var nails = 5;
                var size = 4;

                var bytes = a.Export<byte>(size, order, endianness, nails);
                Assert.AreEqual(0, bytes.Length);

                b.SetTo(1);
                b.Import(bytes, 0, size, order, endianness, nails);
                Assert.AreEqual(a, b);
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:18,代码来源:IO.cs

示例6: IntSquareRoot

        public void IntSquareRoot()
        {
            var n = "8984948281360922385394772450147012613851354303";
            using (var a = new HugeInt(n))
            using (var b = new HugeInt())
            using (var c = new HugeInt())
            {
                a.Value = a * a;

                b.Value = a.SquareRoot();
                Assert.AreEqual(n, b.ToString());

                b.SetTo(0);
                b.Value = (a + 123).SquareRoot().SavingRemainderTo(c);
                Assert.AreEqual(n, b.ToString());
                Assert.AreEqual("123", c.ToString());
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:18,代码来源:Math.cs

示例7: HugeIntSetToPerformedToDefaultPrecision

        public void HugeIntSetToPerformedToDefaultPrecision()
        {
            using (var a = new HugeFloat(14))
            using (var b = new HugeFloat(13))
            using (var c = new HugeFloat("1234523458923405982347445029384572323"))
            using (var d = new HugeInt())
            {
                ShiftLeftBy62(c);
                ShiftLeftBy62(c);
                var expr = a / b + c - c;
                d.SetTo(expr);
                Assert.IsTrue(d == 0);

                HugeFloat.DefaultPrecision = 256;
                d.SetTo(expr);
                Assert.IsTrue(d == 1);
                HugeFloat.DefaultPrecision = 128;
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:19,代码来源:Precision.cs

示例8: IntFitsUint

 public void IntFitsUint()
 {
     using (var a = new HugeInt(uint.MaxValue))
     {
         Assert.IsTrue(a.FitsUint());
         a.Value = a + 1;
         Assert.IsFalse(a.FitsUint());
         a.SetTo(0);
         Assert.IsTrue(a.FitsUint());
         a.Value = a - 1;
         Assert.IsFalse(a.FitsUint());
     }
 }
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Conversions.cs

示例9: IntToAndFromUint

        public void IntToAndFromUint()
        {
            using (var a = new HugeInt())
            {
                uint b = 0xF84739AB;
                a.SetTo(b);
                Assert.AreEqual(b.ToString(), a.ToString());

                a.Value = -a;
                uint c = a.ToUint();
                Assert.AreEqual(b.ToString(), c.ToString());
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Conversions.cs

示例10: IntToAndFromInt

        public void IntToAndFromInt()
        {
            using (var a = new HugeInt())
            {
                int b = -0x784739AB;
                a.SetTo(b);
                Assert.AreEqual(b.ToString(), a.ToString());

                long c = a.ToInt();
                Assert.AreEqual(b.ToString(), c.ToString());
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:12,代码来源:Conversions.cs

示例11: IntToAndFromUlong

        public void IntToAndFromUlong()
        {
            using (var a = new HugeInt())
            {
                ulong b = 0xF84739ABCDEF4876;
                a.SetTo(b);
                Assert.AreEqual(b.ToString(), a.ToString());

                a.Value = -a;
                ulong c = a.ToUlong();
                Assert.AreEqual(b.ToString(), c.ToString());
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Conversions.cs

示例12: IntToAndFromLong

        public void IntToAndFromLong()
        {
            using (var a = new HugeInt())
            {
                long b = -0x784739ABCDEF4876;
                a.SetTo(b);
                Assert.AreEqual(b.ToString(), a.ToString());

                long c = a.ToLong();
                Assert.AreEqual(b.ToString(), c.ToString());
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:12,代码来源:Conversions.cs

示例13: IntToAndFromDouble

        public void IntToAndFromDouble()
        {
            using (var a = new HugeInt())
            using (var lo = new HugeInt())
            using (var hi = new HugeInt())
            {
                var source = Platform.Select(-123.45e20, -123.45e19);
                var zillion = Platform.Ui(10000000000U, 1000000000U);
                var factor = Platform.Ui(1, 10);
                var exp = Platform.Si(0, 0);

                a.SetTo(source);
                lo.Value = (a/zillion).Rounding(RoundingModes.Floor);
                hi.Value = (a/zillion).Rounding(RoundingModes.Ceiling);

                Assert.IsTrue(lo.ToString() == "-1234500000000" || hi.ToString() == "-1234500000000");

                double c = a.ToDouble();
                Assert.AreEqual(source, c);

                a.Value = (a + a) * factor;
                c = a.ToDouble(out exp);

                Assert.AreEqual(75, exp);
                c *= System.Math.Pow(2, exp);

                Assert.IsTrue(a + zillion >= c);
                Assert.IsTrue(a - zillion <= c);
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:30,代码来源:Conversions.cs

示例14: IntFromString

        public void IntFromString()
        {
            using (var a = new HugeInt())
            {
                var n = "98762934876529834765234123984761";
                a.SetTo(n);
                Assert.AreEqual(n, a.ToString());

                n = "-98ABCDEF876529834765234123984761";
                a.SetTo(n, 16);
                Assert.AreEqual(n, a.ToString(16));
            }
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Conversions.cs

示例15: IntFromInvalidString

 public void IntFromInvalidString()
 {
     using (var a = new HugeInt())
     {
         a.SetTo("12345A");
     }
 }
开发者ID:BrianGladman,项目名称:mpir,代码行数:7,代码来源:Conversions.cs


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