本文整理汇总了C#中Rational类的典型用法代码示例。如果您正苦于以下问题:C# Rational类的具体用法?C# Rational怎么用?C# Rational使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rational类属于命名空间,在下文中一共展示了Rational类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAdd_WithOtherRational_Passed
public void TestAdd_WithOtherRational_Passed()
{
var rat = new Rational(625, 5);
var other = new Rational(338, 13);
var sum = rat + other;
Assert.AreEqual(151, (double)sum, "Invalid Sum operation");
}
示例2: TestGetReciprocal
public void TestGetReciprocal()
{
var rational = new Rational(1, 3);
var reciprocal = rational.Reciprocal;
Assert.Equal(new Rational(3, 1), reciprocal);
Assert.Equal(new Rational(1, 3), rational);
}
示例3: DisplayMode
/// <summary>Initializes a new instance of the <see cref="DisplayMode"/> class.</summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="refreshRate">The refresh rate.</param>
public DisplayMode(Format pixelFormat, int width, int height, Rational refreshRate)
{
this.pixelFormat = pixelFormat;
this.width = width;
this.height = height;
this.refreshRate = refreshRate;
}
示例4: EvaluateRational
public override Rational EvaluateRational(int Precision)
{
if (this.power == 0)
{
return 1;
}
else if (this.power == 1)
{
return this.PiSeries(Precision);
}
else if (this.power == -1)
{
return 1 / this.PiSeries(Precision);
}
else if (this.power < -1)
{
Rational newpower = new Rational(this.power.Numerator.Number, this.power.Denominator.Number);
Rational flippedpiseries = 1 / this.PiSeries(Precision);
return PowerEvaluation.EvaluateRationalPower(flippedpiseries, newpower, Precision);
}
else
{
return PowerEvaluation.EvaluateRationalPower(this.PiSeries(Precision), this.power, Precision);
}
}
示例5: TestToSimpleString
public void TestToSimpleString()
{
var third1 = new Rational(1, 3);
var third2 = new Rational(2, 6);
Assert.Equal("1/3", third1.ToSimpleString());
Assert.Equal("1/3", third2.ToSimpleString());
Assert.Equal(third1, third2);
var twoThirds = new Rational(10, 15);
Assert.Equal("2/3", twoThirds.ToSimpleString());
var two = new Rational(10, 5);
Assert.True(two.IsInteger);
Assert.Equal("2", two.ToSimpleString());
Assert.Equal("2", two.ToSimpleString(allowDecimal: false));
var twoFifths = new Rational(4, 10);
Assert.Equal("0.4", twoFifths.ToSimpleString());
Assert.Equal("2/5", twoFifths.ToSimpleString(allowDecimal: false));
var threeEighths = new Rational(3, 8);
Assert.Equal("3/8", threeEighths.ToSimpleString());
var zero = new Rational(0, 8);
Assert.True(zero.IsInteger);
Assert.Equal("0", zero.ToSimpleString());
Assert.Equal("0", zero.ToSimpleString(allowDecimal: false));
zero = new Rational(0, 0);
Assert.True(zero.IsInteger);
Assert.Equal("0", zero.ToSimpleString());
Assert.Equal("0", zero.ToSimpleString(allowDecimal: false));
}
示例6: Generate
private static Datum[] Generate(int count, Rational w0, Rational[] w)
{
return Enumerable.Range(1, count)
.Select(_ => GetX())
.Select(ex => new Datum{x=ex, y=GetY(ex, w0, w)})
.ToArray();
}
示例7: Normalize
public static Rational Normalize(Rational a)
{
int numenator = a.GetNumenator();
int denumenator = a.GetDenumenator();
int gcd = GCD(numenator, denumenator);
return new Rational(numenator / gcd, denumenator / gcd);
}
示例8: TestMinus_WithOtherRational_Passed
public void TestMinus_WithOtherRational_Passed()
{
var rat = new Rational(625, 5);
var other = new Rational(338, 13);
var minus = rat - other;
Assert.AreEqual(99, (double)minus, "Invalid minus operation");
}
示例9: CompareToTest
public void CompareToTest()
{
Rational target = new Rational(1, 3);
Assert.AreEqual(target.CompareTo(new Rational(1, 2)), -1);
Assert.AreEqual(target.CompareTo(new Rational(1, 3)), 0);
Assert.AreEqual(target.CompareTo(new Rational(1, 4)), 1);
}
示例10: TestValue
private static void TestValue(ExifValue value, Rational[] expected)
{
Assert.IsNotNull(value);
Rational[] values = (Rational[])value.Value;
Assert.IsNotNull(values);
CollectionAssert.AreEqual(expected, values);
}
示例11: TestMultiply_WithOtherRational_Passed
public void TestMultiply_WithOtherRational_Passed()
{
var rat = new Rational(625, 5);
var other = new Rational(338, 13);
var mult = rat * other;
Assert.AreEqual(3250, (double)mult, "Invalid multiply operation");
}
示例12: TestCompare_withDoubleFloatInt_Passed
public void TestCompare_withDoubleFloatInt_Passed()
{
var rat = new Rational(625, 5);
Assert.AreEqual(125, (double)rat, "Invalid cast to double");
Assert.AreEqual(125, (float)rat, "Invalid cast to float");
Assert.AreEqual(125, (int)rat, "Invalid cast to int");
}
示例13: ProcessFiles
public static void ProcessFiles(FileInfo[] files, int speedupFactor, Rational outputFramesPerSecond)
{
var i = 1;
var filesCount = files.Count();
var engine = new HyperlapseEngine();
engine.ProcessingCancelled += OnEngineProcessingCancelled;
engine.ProcessingFailed += OnEngineProcessingFailed;
engine.ProcessingFinished += OnEngineProcessingFinished;
engine.ProgressChanged += OnEngineProgressChanged;
engine.TrialStatusChanged += OnEngineTrialStatusChanged;
foreach (var file in files)
{
var processingMsg = "[Processing file " + i++ + " of " + filesCount + "] - " + file.Name;
Console.Title = processingMsg;
Console.WriteLine(processingMsg);
var fileOutput = new FileInfo(Path.Combine(file.DirectoryName, "Output", file.Name));
if (!fileOutput.Directory.Exists)
{
fileOutput.Directory.Create(); // create output dir
}
Process(engine, file, fileOutput, speedupFactor, outputFramesPerSecond);
}
engine.Dispose();
}
示例14: Test_ToDouble
public void Test_ToDouble()
{
Rational rational = new Rational(0, 0);
Assert.AreEqual(double.NaN, rational.ToDouble());
rational = new Rational(2, 0);
Assert.AreEqual(double.PositiveInfinity, rational.ToDouble());
}
示例15: TestCreateRational
public void TestCreateRational()
{
var rational = new Rational(1, 3);
Assert.Equal(1, rational.Numerator);
Assert.Equal(3, rational.Denominator);
Assert.Equal(1d / 3d, rational.ToDouble(), 4);
}