本文整理汇总了C#中Rational.Reduce方法的典型用法代码示例。如果您正苦于以下问题:C# Rational.Reduce方法的具体用法?C# Rational.Reduce怎么用?C# Rational.Reduce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rational
的用法示例。
在下文中一共展示了Rational.Reduce方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: lcm
public static Rational operator +(Rational c1, Rational c2)
{
int newDenom = lcm (c1.d, c2.d);
int n1 = c1.n * newDenom / c1.d;
int n2 = c2.n * newDenom / c2.d;
Rational r = new Rational (n1 + n2, newDenom);
r.Reduce ();
return r;
}
示例2: ReduceTest
public void ReduceTest()
{
Rational target = new Rational(4, 6);
target = target.Reduce();
Assert.AreEqual(target.Numerator, 2);
Assert.AreEqual(target.Denominator, 3);
}
示例3: ReduceTest
public void ReduceTest()
{
Rational r = new Rational(-1, -6);
r.Reduce();
Assert.AreEqual(r.Numerator.Negative, false);
Assert.AreEqual(r.Denominator.Negative, false);
Assert.AreEqual(new BigInteger(1), r.Numerator.Number);
Assert.AreEqual(new BigInteger(6), r.Denominator.Number);
r = new Rational(3, 6);
r.Reduce();
Assert.AreEqual(r.Numerator.Negative, false);
Assert.AreEqual(r.Denominator.Negative, false);
Assert.AreEqual(new BigInteger(1), r.Numerator.Number);
Assert.AreEqual(new BigInteger(2), r.Denominator.Number);
r = new Rational(1, -6);
r.Reduce();
Assert.AreEqual(r.Numerator.Negative, true);
Assert.AreEqual(r.Denominator.Negative, false);
Assert.AreEqual(new BigInteger(1), r.Numerator.Number);
Assert.AreEqual(new BigInteger(6), r.Denominator.Number);
}