public void Expm1Test()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Expm1(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(Math.Exp((double)x) - 1, y, ignore_sign: true);
            }
        }
        public void RcpRawTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = 1 / x;

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(1 / (double)x, y);
            }
        }
        public void AbsTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Abs(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(Math.Abs((double)x), y);
            }
        }
        public void LdexpTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Ldexp(x, 1);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance((double)x * 2, y);
            }

            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Ldexp(x, -1);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance((double)x / 2, y);
            }

            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Ldexp(x, 2);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance((double)x * 4, y);
            }

            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Ldexp(x, -2);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance((double)x / 4, y);
            }
        }
        public void ExpTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Exp(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(Math.Exp((double)x), y);
            }

            Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(
                              MultiPrecision <Pow2.N8> .E,
                              MultiPrecision <Pow2.N8> .Exp(1), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits(
                              MultiPrecision <Pow2.N16> .E,
                              MultiPrecision <Pow2.N16> .Exp(1), 1));
        }
        public void RcpTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Rcp(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(1 / (double)x, y);
            }

            Assert.AreEqual(1, MultiPrecision <Pow2.N8> .Rcp(1));

            Assert.AreEqual(0.5, MultiPrecision <Pow2.N8> .Rcp(2));

            Assert.AreEqual(2, MultiPrecision <Pow2.N8> .Rcp(0.5));

            Assert.AreEqual(1, MultiPrecision <Pow2.N16> .Rcp(1));

            Assert.AreEqual(0.5, MultiPrecision <Pow2.N16> .Rcp(2));

            Assert.AreEqual(2, MultiPrecision <Pow2.N16> .Rcp(0.5));
        }
        public void ToStringTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>().Concat(TestTool.LimitSet <Pow2.N8>()))
            {
                foreach (MultiPrecision <Pow2.N8> v in TestTool.EnumerateNeighbor(x, x.IsZero ? 0 : 2))
                {
                    (Sign sign, Int64 exponent_dec, Accumulator <Pow2.N8> mantissa_dec) = v.ToStringCore(MultiPrecision <Pow2.N8> .DecimalDigits);

                    Console.WriteLine(sign);
                    Console.WriteLine(exponent_dec);
                    Console.WriteLine(mantissa_dec);
                    Console.WriteLine(v.ToString());
                    Console.WriteLine($"{v:E10}");
                    Console.WriteLine(v.ToString("e10"));

                    MultiPrecision <Pow2.N8> u = v.ToString();
                    Console.WriteLine(u.ToString());

                    Console.WriteLine(v.ToHexcode());
                    Console.WriteLine(u.ToHexcode());

                    Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(v, u, 14));
                    Assert.AreEqual((double)v, double.Parse(v.ToString()), Math.Abs((double)v) * 1e-8);
                }
            }

            foreach (MultiPrecision <Pow2.N16> x in TestTool.AllRangeSet <Pow2.N16>().Concat(TestTool.LimitSet <Pow2.N16>()))
            {
                foreach (MultiPrecision <Pow2.N16> v in TestTool.EnumerateNeighbor(x, x.IsZero ? 0 : 2))
                {
                    (Sign sign, Int64 exponent_dec, Accumulator <Pow2.N16> mantissa_dec) = v.ToStringCore(MultiPrecision <Pow2.N16> .DecimalDigits);

                    Console.WriteLine(sign);
                    Console.WriteLine(exponent_dec);
                    Console.WriteLine(mantissa_dec);
                    Console.WriteLine(v.ToString());
                    Console.WriteLine($"{v:E10}");
                    Console.WriteLine(v.ToString("e10"));

                    MultiPrecision <Pow2.N16> u = v.ToString();
                    Console.WriteLine(u.ToString());

                    Console.WriteLine(v.ToHexcode());
                    Console.WriteLine(u.ToHexcode());

                    Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits(v, u, 14));
                    Assert.AreEqual((double)v, double.Parse(v.ToString()), Math.Abs((double)v) * 1e-8);
                }
            }

            for (long i = int.MinValue; i < int.MinValue + 120; i++)
            {
                MultiPrecision <Pow2.N8> v = new MultiPrecision <Pow2.N8>(Sign.Plus, i, Mantissa <Pow2.N8> .One, round: false);

                (Sign sign, Int64 exponent_dec, Accumulator <Pow2.N8> mantissa_dec) = v.ToStringCore(MultiPrecision <Pow2.N8> .DecimalDigits);

                Console.WriteLine(sign);
                Console.WriteLine(exponent_dec);
                Console.WriteLine(mantissa_dec);
                Console.WriteLine(v.ToString());
                Console.WriteLine($"{v:E10}");
                Console.WriteLine(v.ToString("e10"));

                MultiPrecision <Pow2.N8> u = v.ToString();
                Console.WriteLine(u.ToString());

                Console.WriteLine(v.ToHexcode());
                Console.WriteLine(u.ToHexcode());

                Assert.AreEqual((double)v, double.Parse(v.ToString()), Math.Abs((double)v) * 1e-8);
            }

            for (long i = int.MaxValue - 120; i < int.MaxValue; i++)
            {
                MultiPrecision <Pow2.N8> v = new MultiPrecision <Pow2.N8>(Sign.Plus, i, Mantissa <Pow2.N8> .One, round: false);

                (Sign sign, Int64 exponent_dec, Accumulator <Pow2.N8> mantissa_dec) = v.ToStringCore(MultiPrecision <Pow2.N8> .DecimalDigits);

                Console.WriteLine(sign);
                Console.WriteLine(exponent_dec);
                Console.WriteLine(mantissa_dec);
                Console.WriteLine(v.ToString());
                Console.WriteLine($"{v:E10}");
                Console.WriteLine(v.ToString("e10"));

                MultiPrecision <Pow2.N8> u = v.ToString();
                Console.WriteLine(u.ToString());

                Console.WriteLine(v.ToHexcode());
                Console.WriteLine(u.ToHexcode());

                Assert.AreEqual((double)v, double.Parse(v.ToString()), Math.Abs((double)v) * 1e-8);
            }

            {
                MultiPrecision <Pow2.N8> v = MultiPrecision <Pow2.N8> .PI;

                (Sign sign, Int64 exponent_dec, Accumulator <Pow2.N8> mantissa_dec) = v.ToStringCore(MultiPrecision <Pow2.N8> .DecimalDigits);

                Console.WriteLine(sign);
                Console.WriteLine(exponent_dec);
                Console.WriteLine(mantissa_dec);
                Console.WriteLine(v.ToString());
                Console.WriteLine($"{v:E10}");
                Console.WriteLine(v.ToString("e10"));

                MultiPrecision <Pow2.N8> u = v.ToString();
                Console.WriteLine(u.ToString());

                Console.WriteLine(v.ToHexcode());
                Console.WriteLine(u.ToHexcode());

                Assert.AreEqual((double)v, double.Parse(v.ToString()), Math.Abs((double)v) * 1e-8);
            }

            string p99 = "0.999";

            for (int i = 0; i < 100; i++)
            {
                p99 += "9";

                MultiPrecision <Pow2.N8> u = p99;
                Console.WriteLine(u.ToString());
                Console.WriteLine(u.ToHexcode());

                Assert.AreEqual(double.Parse(p99), (double)u, 1e-100);
            }
        }
        public void ErfTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Erf(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(ErfApprox((double)x), y, minerr: 1e-2, ignore_sign: true);
            }

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "-9.999999845827420997199811478403265131159514278547464108088316571e-1",
                    MultiPrecision <Pow2.N8> .Erf(-4),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "-9.999779095030014145586272238704176796201522929126007503427610452e-1",
                    MultiPrecision <Pow2.N8> .Erf(-3),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "-9.953222650189527341620692563672529286108917970400600767383523262e-1",
                    MultiPrecision <Pow2.N8> .Erf(-2),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "-8.427007929497148693412206350826092592960669979663029084599378978e-1",
                    MultiPrecision <Pow2.N8> .Erf(-1),
                    "1e-50"
                    ));

            Assert.AreEqual(0, MultiPrecision <Pow2.N8> .Erf(0));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "8.427007929497148693412206350826092592960669979663029084599378978e-1",
                    MultiPrecision <Pow2.N8> .Erf(1),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "9.953222650189527341620692563672529286108917970400600767383523262e-1",
                    MultiPrecision <Pow2.N8> .Erf(2),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "9.999779095030014145586272238704176796201522929126007503427610452e-1",
                    MultiPrecision <Pow2.N8> .Erf(3),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "9.999999845827420997199811478403265131159514278547464108088316571e-1",
                    MultiPrecision <Pow2.N8> .Erf(4),
                    "1e-50"
                    ));
        }
        public void ErfcTest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Erfc(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(ErfcApprox((double)x), y, minerr: 1e-2, ignore_sign: true);
            }

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.9999999845827420997199811478403265131159514278547464108088316571e0",
                    MultiPrecision <Pow2.N8> .Erfc(-4),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.9999779095030014145586272238704176796201522929126007503427610452e0",
                    MultiPrecision <Pow2.N8> .Erfc(-3),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.9953222650189527341620692563672529286108917970400600767383523262e0",
                    MultiPrecision <Pow2.N8> .Erfc(-2),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.8427007929497148693412206350826092592960669979663029084599378978e0",
                    MultiPrecision <Pow2.N8> .Erfc(-1),
                    "1e-50"
                    ));

            Assert.AreEqual(1, MultiPrecision <Pow2.N8> .Erfc(0));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.572992070502851306587793649173907407039330020336970915400621022e-1",
                    MultiPrecision <Pow2.N8> .Erfc(1),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "4.677734981047265837930743632747071389108202959939923261647673800e-3",
                    MultiPrecision <Pow2.N8> .Erfc(2),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "2.209049699858544137277612958232037984770708739924965723895484294e-5",
                    MultiPrecision <Pow2.N8> .Erfc(3),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.541725790028001885215967348688404857214525358919116834290499421e-8",
                    MultiPrecision <Pow2.N8> .Erfc(4),
                    "1e-50"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "2.088487583762544757000786294957788611560818119321163727012213714e-45",
                    MultiPrecision <Pow2.N8> .Erfc(10),
                    "1e-95"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "2.070920778841656048448447875165788792932250920995399683766235534e-1088",
                    MultiPrecision <Pow2.N8> .Erfc(50),
                    "1e-1138"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "6.405961424921732039021339148586394148214414399460338057767107650e-4346",
                    MultiPrecision <Pow2.N8> .Erfc(100),
                    "1e-4396"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "2.703823745452247856854931734255359377805490749772707768226770978e-108577",
                    MultiPrecision <Pow2.N8> .Erfc(500),
                    "1e-108627"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.860037048632323370908471162289984373206233539926488472200712370e-434298",
                    MultiPrecision <Pow2.N8> .Erfc(1000),
                    "1e-434348"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.011285440970039477031542173737947576392096400158950800837668262e-10857366",
                    MultiPrecision <Pow2.N8> .Erfc(5000),
                    "1e-10857416"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "3.639987386564198052838435239316275600299066983050320050544858948e-43429453",
                    MultiPrecision <Pow2.N8> .Erfc(10000),
                    "1e-43429303"
                    ));

            Assert.IsTrue(
                MultiPrecision <Pow2.N8> .NearlyEquals(
                    "1.969361711624327154389174953238654441985348792810296010912403861e-1085736210",
                    MultiPrecision <Pow2.N8> .Erfc(50000),
                    "1e-1085736260"
                    ));
        }