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


C# HugeFloat.ToString方法代码示例

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


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

示例1: FloatInputOutputStr62

        public void FloatInputOutputStr62()
        {
            using(var a = new HugeFloat("10123456789ABCDEF012345.6789ABCDE", 16))
            using(var b = HugeFloat.Allocate(12800))
            using(var ms = new MemoryStream())
            {
                a.Reallocate(12800);
                a.Value = a ^ 100;
                using(var writer = new StreamWriter(ms, Encoding.UTF8, 1024, true))
                    a.Write(writer, 62, 0, false, false);

                ms.Position = 0;

                using(var reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true))
                    b.Read(reader, 62, false);

                Assert.AreEqual(a.ToString(62), b.ToString(62));
                Assert.AreEqual(ms.Length, ms.Position);
                Assert.AreEqual((char)0xFEFF + a.ToString(62), Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
开发者ID:wbhart,项目名称:mpir,代码行数:21,代码来源:IO.cs

示例2: AreEqual

        public static void AreEqual(string expected, HugeFloat actual)
        {
            var actualStr = actual.ToString();
            if(expected[0] == '-')
            {
                Assert.AreEqual(expected[0], actualStr[0]);
                actualStr = actualStr.TrimStart('-');
                expected = expected.TrimStart('-');
            }

            var exponent = expected.IndexOf('.');
            if(exponent < 0) exponent = expected.Length;
            expected = expected.Replace(".", "");

            var exponentStr = "@" + exponent;

            Assert.IsTrue(actualStr.StartsWith("0."));
            actualStr = actualStr.Substring(2);

            Assert.IsTrue(actualStr.EndsWith(exponentStr));
            actualStr = actualStr.Substring(0, actualStr.Length - exponentStr.Length);

            if (expected.Length > actualStr.Length)
            {
                var roundedUp = expected[actualStr.Length] >= '5';
                expected = expected.Substring(0, actualStr.Length);
                if(roundedUp)
                {
                    using (var a = new HugeInt(expected))
                    {
                        a.Value += 1;
                        expected = a.ToString(10);
                    }
                }
            }
            Assert.AreEqual(expected, actualStr);
        }
开发者ID:BrianGladman,项目名称:mpir,代码行数:37,代码来源:Arithmetic.cs

示例3: ExpressionsCalculatedToDestinationPrecision

 public void ExpressionsCalculatedToDestinationPrecision()
 {
     using (var a = new HugeFloat(1))
     using (var b = new HugeFloat(3))
     using (var c = new HugeFloat(5))
     using (var d = new HugeFloat(a / b + c))
     {
         Assert.AreEqual("[email protected]", d.ToString());
         d.Reallocate(256);
         d.Value = a / b + c;
         Assert.AreEqual("0.533333333333333[email protected]1", d.ToString());
     }
 }
开发者ID:wbhart,项目名称:mpir,代码行数:13,代码来源:Precision.cs


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