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


C# Rational类代码示例

本文整理汇总了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");
 }
开发者ID:fanatt20,项目名称:RationalMath,代码行数:7,代码来源:Rational.Tests.cs

示例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);
 }
开发者ID:yjqGitHub,项目名称:metadata-extractor-dotnet,代码行数:7,代码来源:RationalTest.cs

示例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;
 }
开发者ID:GrafSeismo,项目名称:SharpDX,代码行数:12,代码来源:DisplayMode.cs

示例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);
     }
 }
开发者ID:samphippen,项目名称:precmaths,代码行数:25,代码来源:PiSymbol.cs

示例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));
        }
开发者ID:proglobyte,项目名称:metadata-extractor-dotnet,代码行数:33,代码来源:RationalTest.cs

示例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();
 }
开发者ID:jschlitz,项目名称:SupportVec2,代码行数:7,代码来源:Program.cs

示例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);
 }
开发者ID:seniorivn,项目名称:ITMO,代码行数:7,代码来源:task1.cs

示例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");
 }
开发者ID:fanatt20,项目名称:RationalMath,代码行数:7,代码来源:Rational.Tests.cs

示例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);
 }
开发者ID:rettour,项目名称:Labs,代码行数:7,代码来源:RationalTest.cs

示例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);
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:7,代码来源:ExifProfileTests.cs

示例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");
 }
开发者ID:fanatt20,项目名称:RationalMath,代码行数:7,代码来源:Rational.Tests.cs

示例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");
 }
开发者ID:fanatt20,项目名称:RationalMath,代码行数:7,代码来源:Rational.Tests.cs

示例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();
        }
开发者ID:joaompneves,项目名称:HyperlapseBatchProcessor,代码行数:29,代码来源:HyperlapseWrapper.cs

示例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());
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:8,代码来源:RationalTests.cs

示例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);
        }
开发者ID:proglobyte,项目名称:metadata-extractor-dotnet,代码行数:8,代码来源:RationalTest.cs


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