本文整理汇总了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;
}