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


C# ComplexNumber类代码示例

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


ComplexNumber类属于命名空间,在下文中一共展示了ComplexNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Simple

        public void Simple()
        {
            var complexNumber1 = new ComplexNumber(1, 2);
            var complexNumber2 = new ComplexNumber(3, 4);
            var multiplyComplexNumber = complexNumber1.Multiply(complexNumber2);

            Assert.AreEqual(1 * 3 - 2 * 4, multiplyComplexNumber.Real);
            Assert.AreEqual(2 * 3 + 1 * 4, multiplyComplexNumber.Imaginary);

            multiplyComplexNumber = complexNumber1.Multiply(5);
            Assert.AreEqual(5 * 1, multiplyComplexNumber.Real);
            Assert.AreEqual(5 * 2, multiplyComplexNumber.Imaginary);

            multiplyComplexNumber = 6 * complexNumber1;
            Assert.AreEqual(6 * 1, multiplyComplexNumber.Real);
            Assert.AreEqual(6 * 2, multiplyComplexNumber.Imaginary);

            multiplyComplexNumber = complexNumber1 * 7;
            Assert.AreEqual(7 * 1, multiplyComplexNumber.Real);
            Assert.AreEqual(7 * 2, multiplyComplexNumber.Imaginary);

            complexNumber1 *= 1;
            Assert.AreEqual(1, complexNumber1.Real);
            Assert.AreEqual(2, complexNumber1.Imaginary);

            complexNumber1 *= 5;
            Assert.AreEqual(5, complexNumber1.Real);
            Assert.AreEqual(10, complexNumber1.Imaginary);

            complexNumber1 *= complexNumber2;
            Assert.AreEqual(5 * 3 - 10 * 4, complexNumber1.Real);
            Assert.AreEqual(10 * 3 + 5 * 4, complexNumber1.Imaginary);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:33,代码来源:Times.cs

示例2: Simple2

        public void Simple2()
        {
            var complexNumber1 = new ComplexNumber(4, 3);
            var complexNumber2 = new ComplexNumber(6, 2);
            var complexNumber3 = new ComplexNumber(-2, -4);
            var complexNumber4 = new ComplexNumber(3, -8);
            var complexNumber5 = new ComplexNumber(8, 3);

            var resultComplexNumber = complexNumber1 + complexNumber2;

            Assert.AreEqual(10, resultComplexNumber.Real);
            Assert.AreEqual(5, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber1 + complexNumber3;

            Assert.AreEqual(2, resultComplexNumber.Real);
            Assert.AreEqual(-1, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber1 + complexNumber4;

            Assert.AreEqual(7, resultComplexNumber.Real);
            Assert.AreEqual(-5, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber1 + complexNumber5;

            Assert.AreEqual(12, resultComplexNumber.Real);
            Assert.AreEqual(6, resultComplexNumber.Imaginary);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:28,代码来源:Plus.cs

示例3: ExecuteWithParamsTest

        public void ExecuteWithParamsTest()
        {
            var complex = new Complex(5, 2);
            var exp = new ComplexNumber(complex);

            Assert.Equal(complex, exp.Execute(null));
        }
开发者ID:sys27,项目名称:xFunc,代码行数:7,代码来源:ComplexNumberTest.cs

示例4: Simple1

        public void Simple1()
        {
            var complexNumber1 = new ComplexNumber(4, 3);
            var complexNumber2 = new ComplexNumber(6, 2);
            var complexNumber3 = new ComplexNumber(-2, -4);
            var complexNumber4 = new ComplexNumber(3, -8);
            var complexNumber5 = new ComplexNumber(8, 3);

            var resultComplexNumber = complexNumber1.Subtract(complexNumber2);

            Assert.AreEqual(1, resultComplexNumber.Imaginary);
            Assert.AreEqual(-2, resultComplexNumber.Real);

            resultComplexNumber = complexNumber1.Subtract(complexNumber3);

            Assert.AreEqual(7, resultComplexNumber.Imaginary);
            Assert.AreEqual(6, resultComplexNumber.Real);

            resultComplexNumber = complexNumber1.Subtract(complexNumber4);

            Assert.AreEqual(11, resultComplexNumber.Imaginary);
            Assert.AreEqual(1, resultComplexNumber.Real);

            resultComplexNumber = complexNumber1.Subtract(complexNumber5);

            Assert.AreEqual(0, resultComplexNumber.Imaginary);
            Assert.AreEqual(-4, resultComplexNumber.Real);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:28,代码来源:Minus.cs

示例5: EqualsTest

        public void EqualsTest()
        {
            var exp1 = new ComplexNumber(new Complex(5, 2));
            var exp2 = new ComplexNumber(new Complex(5, 2));

            Assert.True(exp1.Equals(exp2));
        }
开发者ID:sys27,项目名称:xFunc,代码行数:7,代码来源:ComplexNumberTest.cs

示例6: ExecuteTest

        public void ExecuteTest()
        {
            var complex = new Complex(5, 2);
            var exp = new ComplexNumber(complex);

            Assert.Equal(complex, exp.Execute());
        }
开发者ID:sys27,项目名称:xFunc,代码行数:7,代码来源:ComplexNumberTest.cs

示例7: Simple

        public void Simple()
        {
            var complexNumber = new ComplexNumber(5, 6);
            var copy = (ComplexNumber) complexNumber.Clone();

            Assert.AreEqual(copy.Real, complexNumber.Real);
            Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);

            complexNumber = new ComplexNumber(-2, 3);
            copy = (ComplexNumber) complexNumber.Clone();

            Assert.AreEqual(copy.Real, complexNumber.Real);
            Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);

            complexNumber = new ComplexNumber(5, -3);
            copy = (ComplexNumber) complexNumber.Clone();

            Assert.AreEqual(copy.Real, complexNumber.Real);
            Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);

            complexNumber = new ComplexNumber(-9, -4);
            copy = (ComplexNumber) complexNumber.Clone();

            Assert.AreEqual(copy.Real, complexNumber.Real);
            Assert.AreEqual(copy.Imaginary, complexNumber.Imaginary);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:26,代码来源:Clone.cs

示例8: Simple

        public void Simple()
        {
            var complexNumber1 = new ComplexNumber(4, 5);
            var complexNumber2 = new ComplexNumber(-2, 4);
            var complexNumber3 = new ComplexNumber(1, -3);
            var complexNumber4 = new ComplexNumber(-6, -12);

            var resultComplexNumber = complexNumber1.Reciprocal;

            Assert.AreEqual(4d / 41d, resultComplexNumber.Real);
            Assert.AreEqual(-5d / 41d, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber2.Reciprocal;

            Assert.AreEqual(-2d / 20d, resultComplexNumber.Real);
            Assert.AreEqual(-4d / 20d, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber3.Reciprocal;

            Assert.AreEqual(1d / 10d, resultComplexNumber.Real);
            Assert.AreEqual(3d / 10d, resultComplexNumber.Imaginary);

            resultComplexNumber = complexNumber4.Reciprocal;

            Assert.AreEqual(-6d / 180d, resultComplexNumber.Real);
            Assert.AreEqual(12d / 180d, resultComplexNumber.Imaginary);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:27,代码来源:Reciprocal.cs

示例9: CanAdd

 public ComplexNumber CanAdd(ComplexNumber x, ComplexNumber y)
 {
     ComplexNumber result = x + y;
     Assert.AreEqual(x.Real + y.Real, result.Real);
     Assert.AreEqual(x.Imaginary + y.Imaginary, result.Imaginary);
     return result;
 }
开发者ID:bazile,项目名称:Training,代码行数:7,代码来源:ComplexNumberFixture.cs

示例10: Main

    public static void Main( string[] args )
    {
        // declare two variables to store complex numbers
          // to be entered by user
          ComplexNumber x, y;

          // prompt the user to enter the first complex number
          Console.Write( "Enter the real part of complex number x: " );
          double realPart = Convert.ToDouble( Console.ReadLine() );
          Console.Write(
         "Enter the imaginary part of complex number x: " );
          double imaginaryPart = Convert.ToDouble( Console.ReadLine() );
          x = new ComplexNumber( realPart, imaginaryPart );

          // prompt the user to enter the second complex number
          Console.Write( "\nEnter the real part of complex number y: " );
          realPart = Convert.ToDouble( Console.ReadLine() );
          Console.Write(
         "Enter the imaginary part of complex number y: " );
          imaginaryPart = Convert.ToDouble( Console.ReadLine() );
          y = new ComplexNumber( realPart, imaginaryPart );

          // display the results of calculations with x and y
          Console.WriteLine();
          Console.WriteLine( "{0} + {1} = {2}", x, y, x + y );
          Console.WriteLine( "{0} - {1} = {2}", x, y, x - y );
          Console.WriteLine( "{0} * {1} = {2}", x, y, x * y );
    }
开发者ID:Kazempour,项目名称:src,代码行数:28,代码来源:OperatorOverloading.cs

示例11: SumNumbers

 public void SumNumbers()
 {
     ComplexNumber n1 = new ComplexNumber(1,1);
     ComplexNumber n2 = new ComplexNumber(1,1);
     ComplexNumber result = n1 + n2;
     Assert.AreEqual(2, result.Real);
     Assert.AreEqual(2, result.Imaginary);
 }
开发者ID:tecnocrata,项目名称:Tecnocrata-Mathematics,代码行数:8,代码来源:ComplexNumberTests.cs

示例12: MulNumbers

 public void MulNumbers()
 {
     ComplexNumber n1 = new ComplexNumber(3, 5);
     ComplexNumber n2 = new ComplexNumber(2, 3);
     ComplexNumber result = n1 * n2;
     Assert.AreEqual(6, result.Real);
     Assert.AreEqual(15, result.Imaginary);
 }
开发者ID:tecnocrata,项目名称:Tecnocrata-Mathematics,代码行数:8,代码来源:ComplexNumberTests.cs

示例13: DivNumbers

 public void DivNumbers()
 {
     ComplexNumber n1 = new ComplexNumber(3, 15);
     ComplexNumber n2 = new ComplexNumber(2, 3);
     ComplexNumber result = n1 / n2;
     Assert.AreEqual(1.5, result.Real);
     Assert.AreEqual(5, result.Imaginary);
 }
开发者ID:tecnocrata,项目名称:Tecnocrata-Mathematics,代码行数:8,代码来源:ComplexNumberTests.cs

示例14: DiffNumbers

 public void DiffNumbers()
 {
     ComplexNumber n1 = new ComplexNumber(1, 1);
     ComplexNumber n2 = new ComplexNumber(1, 1);
     ComplexNumber result = n1 - n2;
     Assert.AreEqual(0, result.Real);
     Assert.AreEqual(0, result.Imaginary);
 }
开发者ID:tecnocrata,项目名称:Tecnocrata-Mathematics,代码行数:8,代码来源:ComplexNumberTests.cs

示例15: CalculateMandelbrotIterations

 private static int CalculateMandelbrotIterations(ComplexNumber current, ComplexNumber start, int iterations,int maxiterations)
 {
     if (iterations >= maxiterations)
         return maxiterations;
     if (current.LengthSquared() > 4f)
         return iterations;
     return CalculateMandelbrotIterations(current * current + start, start, ++iterations,maxiterations);
 }
开发者ID:12354,项目名称:Math-Evaluator,代码行数:8,代码来源:Mandelbrot.cs


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