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


C# BigDecimal.Remainder方法代码示例

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


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

示例1: ModPi

        public static BigDecimal ModPi(BigDecimal x)
        {
            /* write x= pi*k+r with the precision in r defined by the precision of x and not
                * compromised by the precision of pi, so the ulp of pi*k should match the ulp of x.
                * First get a guess of k to figure out how many digits of pi are needed.
                */
            var k = (int) (x.ToDouble()/System.Math.PI);

            /* want to have err(pi*k)< err(x)=x.ulp/2, so err(pi) = err(x)/(2k) with two safety digits
                */
            double errpi;
            if (k != 0)
                errpi = 0.5*System.Math.Abs(x.Ulp().ToDouble()/k);
            else
                errpi = 0.5*System.Math.Abs(x.Ulp().ToDouble());
            var mc = new MathContext(2 + ErrorToPrecision(3.1416, errpi));
            BigDecimal onepi = PiRound(mc);
            BigDecimal pihalf = onepi.Divide(new BigDecimal(2));

            /* Delegate the actual operation to the BigDecimal class, which may return
                * a negative value of x was negative .
                */
            BigDecimal res = x.Remainder(onepi);
            if (res.CompareTo(pihalf) > 0)
                res = res.Subtract(onepi);
            else if (res.CompareTo(pihalf.Negate()) < 0)
                res = res.Add(onepi);

            /* The actual precision is set by the input value, its absolute value of x.ulp()/2.
                */
            mc = new MathContext(ErrorToPrecision(res.ToDouble(), x.Ulp().ToDouble()/2d));
            return res.Round(mc);
        }
开发者ID:tupunco,项目名称:deveel-math,代码行数:33,代码来源:BigMath.cs

示例2: Mod2Pi

        public static BigDecimal Mod2Pi(BigDecimal x)
        {
            /* write x= 2*pi*k+r with the precision in r defined by the precision of x and not
                * compromised by the precision of 2*pi, so the ulp of 2*pi*k should match the ulp of x.
                * First get a guess of k to figure out how many digits of 2*pi are needed.
                */
            var k = (int) (0.5*x.ToDouble()/System.Math.PI);

            /* want to have err(2*pi*k)< err(x)=0.5*x.ulp, so err(pi) = err(x)/(4k) with two safety digits
                */
            double err2pi;
            if (k != 0)
                err2pi = 0.25*System.Math.Abs(x.Ulp().ToDouble()/k);
            else
                err2pi = 0.5*System.Math.Abs(x.Ulp().ToDouble());
            var mc = new MathContext(2 + ErrorToPrecision(6.283, err2pi));
            BigDecimal twopi = PiRound(mc).Multiply(new BigDecimal(2));

            /* Delegate the actual operation to the BigDecimal class, which may return
                * a negative value of x was negative .
                */
            BigDecimal res = x.Remainder(twopi);
            if (res.CompareTo(BigDecimal.Zero) < 0)
                res = res.Add(twopi);

            /* The actual precision is set by the input value, its absolute value of x.ulp()/2.
                */
            mc = new MathContext(ErrorToPrecision(res.ToDouble(), x.Ulp().ToDouble()/2d));
            return res.Round(mc);
        }
开发者ID:tupunco,项目名称:deveel-math,代码行数:30,代码来源:BigMath.cs

示例3: RemainderMathContextHALF_DOWN

 public void RemainderMathContextHALF_DOWN()
 {
     String a = "3736186567876876578956958765675671119238118911893939591735";
     int aScale = -45;
     String b = "134432345432345748766876876723342238476237823787879183470";
     int bScale = 10;
     int precision = 75;
     RoundingMode rm = RoundingMode.HalfDown;
     MathContext mc = new MathContext(precision, rm);
     String res = "1149310942946292909508821656680979993738625937.2065885780";
     int resScale = 10;
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     BigDecimal result = aNumber.Remainder(bNumber, mc);
     Assert.AreEqual(res, result.ToString(), "incorrect quotient value");
     Assert.AreEqual(resScale, result.Scale, "incorrect quotient scale");
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:17,代码来源:BigDecimalArithmeticTest.cs

示例4: RemainderMathContextHALF_UP

 public void RemainderMathContextHALF_UP()
 {
     String a = "3736186567876876578956958765675671119238118911893939591735";
     int aScale = 45;
     String b = "134432345432345748766876876723342238476237823787879183470";
     int bScale = 10;
     int precision = 15;
     RoundingMode rm = RoundingMode.HalfUp;
     MathContext mc = new MathContext(precision, rm);
     String res = "3736186567876.876578956958765675671119238118911893939591735";
     int resScale = 45;
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     BigDecimal result = aNumber.Remainder(bNumber, mc);
     Assert.AreEqual(res, result.ToString(), "incorrect quotient value");
     Assert.AreEqual(resScale, result.Scale, "incorrect quotient scale");
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:17,代码来源:BigDecimalArithmeticTest.cs

示例5: Remainder2

 public void Remainder2()
 {
     String a = "3736186567876876578956958765675671119238118911893939591735";
     int aScale = -45;
     String b = "134432345432345748766876876723342238476237823787879183470";
     int bScale = 10;
     String res = "1149310942946292909508821656680979993738625937.2065885780";
     int resScale = 10;
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     BigDecimal result = aNumber.Remainder(bNumber);
     Assert.AreEqual(res, result.ToString(), "incorrect quotient value");
     Assert.AreEqual(resScale, result.Scale, "incorrect quotient scale");
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:14,代码来源:BigDecimalArithmeticTest.cs


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