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


C# Rational.Clone方法代码示例

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


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

示例1: EvaluateRationalPower

        public static Rational EvaluateRationalPower(Rational a, Rational power,int precision)
        {
            if (a < 0)
            {
                throw new NotImplementedException("exponentation of negative numbers not yet supported");
            }
            SignedBigInteger normalexponentiations = power.Numerator / power.Denominator;
            SignedBigInteger funkyexponentiation = power.Numerator % power.Denominator;
            Rational result;
            if (normalexponentiations > 0)
            {
                result = a.Clone();
                for (int i = 1; i < normalexponentiations; i++)
                {
                    result *= a;
                }
            }
            else
            {
                result = 1;
            }
            Rational upperbound;
            if (a > 1)
            {
                upperbound = a.Clone();
            }
            else
            {
                upperbound = new Rational(a.Denominator, a.Numerator);
            }
            SignedBigInteger flippedtarget = power.Denominator;
            Rational lowerbound = 0;
            Rational target = upperbound.Clone();
            for (long i = 0; i < precision * 5; i++)
            {
                Rational error = (upperbound - lowerbound) / 2;
                Rational guess = lowerbound + error;
                Rational bound = guess.Clone();
                for (int j = 1; j < flippedtarget; j++)
                {
                    guess *= bound;
                }
                if (guess > target)
                {
                    upperbound = bound;
                }
                if (guess < target)
                {
                    lowerbound = bound;
                }

            }
            for (int i = 0; i < funkyexponentiation; i++)
            {
                result *= lowerbound;
            }
            return result;
        }
开发者ID:samphippen,项目名称:precmaths,代码行数:58,代码来源:PowerEvaluation.cs


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