• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Rational类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Rational类属于命名空间,在下文中一共展示了Rational类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TestDivide_WithOtherRational_Passed

 public void TestDivide_WithOtherRational_Passed()
 {
     var rat = new Rational(7, 5);
     var other = new Rational(5, 7);
     var div = rat / other;
     Assert.AreEqual(49, div.Numerator, "Invalid divide operation");
     Assert.AreEqual(25, div.Denominator, "Invalid divide operation");
 }
开发者ID:fanatt20,项目名称:RationalMath,代码行数:8,代码来源:Rational.Tests.cs


示例17: 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


示例18: RendererConfiguration

 public RendererConfiguration(int backBufferWidth, int backBufferHeight, Format backBufferFormat,
     Rational refreshRate, bool windowed)
 {
     BackBufferWidth = backBufferWidth;
     BackBufferHeight = backBufferHeight;
     BackBufferFormat = backBufferFormat;
     RefreshRate = refreshRate;
     Windowed = windowed;
 }
开发者ID:TheProjecter,项目名称:romantiquex,代码行数:9,代码来源:RendererConfiguration.cs


示例19: Create

 /// <summary>
 /// Creates array of rationals from array of integers
 /// </summary>
 /// <param name="values"></param>
 /// <returns></returns>
 public static Rational<long, Int64Policy>[] Create(long[] values)
 {
     var result = new Rational<long, Int64Policy>[values.Length];
     for(var i = 0; i < values.Length; i++)
     {
         result[i] = new Rational<long, Int64Policy>(values[i]);
     }
     return result;
 }
开发者ID:svejdo1,项目名称:SymbolicMath,代码行数:14,代码来源:RationalFactory.cs


示例20: ModeDescription

 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.DXGI.ModeDescription" /> structure.
 /// </summary>
 /// <param name = "width">The width.</param>
 /// <param name = "height">The height.</param>
 /// <param name = "refreshRate">The refresh rate.</param>
 /// <param name = "format">The format.</param>
 public ModeDescription(int width, int height, Rational refreshRate, Format format)
 {
     this.Width = width;
     this.Height = height;
     this.RefreshRate = refreshRate;
     this.Format = format;
     this.ScanlineOrdering = DisplayModeScanlineOrder.Unspecified;
     this.Scaling = DisplayModeScaling.Unspecified;
 }
开发者ID:alexey-bez,项目名称:SharpDX,代码行数:16,代码来源:ModeDescription.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RavenConfiguration类代码示例发布时间:2022-05-24
下一篇:
C# Rating类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap