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

C# Complex结构体代码示例

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

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



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

示例1: Main

//引入命名空间
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      // Create a complex number by calling its class constructor.
      Complex c1 = new Complex(12, 6);
      Console.WriteLine(c1);
      
      // Assign a Double to a complex number.
      Complex c2 = 3.14;
      Console.WriteLine(c2);
      
      // Cast a Decimal to a complex number.
      Complex c3 = (Complex) 12.3m;
      Console.WriteLine(c3);
      
      // Assign the return value of a method to a Complex variable.
      Complex c4 = Complex.Pow(Complex.One, -1);
      Console.WriteLine(c4);
      
      // Assign the value returned by an operator to a Complex variable.
      Complex c5 = Complex.One + Complex.One;
      Console.WriteLine(c5);

      // Instantiate a complex number from its polar coordinates.
      Complex c6 = Complex.FromPolarCoordinates(10, .524);
      Console.WriteLine(c6);
   }
}
开发者ID:.NET开发者,项目名称:System.Numerics,代码行数:33,代码来源:Complex

输出:

(12, 6)
(3.14, 0)
(12.3, 0)
(1, 0)
(2, 0)
(8.65824721882145, 5.00347430269914)


示例2: Complex

Complex value = new Complex(Double.MinValue/2, Double.MinValue/2);
Complex value2 = Complex.Exp(Complex.Log(value));
Console.WriteLine("{0} \n{1} \nEqual: {2}", value, value2, 
                                            value == value2);
开发者ID:.NET开发者,项目名称:System.Numerics,代码行数:4,代码来源:Complex

输出:

(-8.98846567431158E+307, -8.98846567431158E+307)
(-8.98846567431161E+307, -8.98846567431161E+307)
Equal: False


示例3: Main

//引入命名空间
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex c1 = new Complex(Double.MaxValue / 2, Double.MaxValue /2);

      Complex c2 = c1 / Complex.Zero;
      Console.WriteLine(c2.ToString());
      c2 = c2 * new Complex(1.5, 1.5);
      Console.WriteLine(c2.ToString());
      Console.WriteLine();
      
      Complex c3 = c1 * new Complex(2.5, 3.5);
      Console.WriteLine(c3.ToString());
      c3 = c3 + new Complex(Double.MinValue / 2, Double.MaxValue / 2); 
      Console.WriteLine(c3);
   }
}
开发者ID:.NET开发者,项目名称:System.Numerics,代码行数:22,代码来源:Complex

输出:

(NaN, NaN)
(NaN, NaN)
(NaN, Infinity)
(NaN, Infinity)


示例4: GetFormat

//引入命名空间
using System;
using System.Numerics;

public class ComplexFormatter :IFormatProvider, ICustomFormatter
{
   public object GetFormat(Type formatType) 
   {   
      if (formatType == typeof(ICustomFormatter))
         return this;
      else
         return null;
   }
   
   public string Format(string format, object arg, 
                        IFormatProvider provider)
   {
      if (arg is Complex)
      {
         Complex c1 = (Complex) arg; 
         // Check if the format string has a precision specifier.
         int precision;
         string fmtString = String.Empty;
         if (format.Length > 1) {
            try {
               precision = Int32.Parse(format.Substring(1));
            }
            catch (FormatException) {
               precision = 0;
            }
            fmtString = "N" + precision.ToString();
         }
         if (format.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase))
            return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "i";
         else if (format.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase))
            return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "j";
         else
            return c1.ToString(format, provider);
      }
      else
      {
         if (arg is IFormattable)
            return ((IFormattable) arg).ToString(format, provider);
         else if (arg != null) 
            return arg.ToString();
         else
            return String.Empty;
      }                        
   }
}
开发者ID:.NET开发者,项目名称:System.Numerics,代码行数:50,代码来源:Complex


示例5: Main

public class Example
{
   public static void Main()
   {
      Complex c1 = new Complex(12.1, 15.4);
      Console.WriteLine("Formatting with ToString():       " + 
                        c1.ToString());
      Console.WriteLine("Formatting with ToString(format): " + 
                        c1.ToString("N2"));
      Console.WriteLine("Custom formatting with I0:        " + 
                        String.Format(new ComplexFormatter(), "{0:I0}", c1));
      Console.WriteLine("Custom formatting with J3:        " + 
                        String.Format(new ComplexFormatter(), "{0:J3}", c1));
   }
}
开发者ID:.NET开发者,项目名称:System.Numerics,代码行数:15,代码来源:Complex

输出:

Formatting with ToString():       (12.1, 15.4)
Formatting with ToString(format): (12.10, 15.40)
Custom formatting with I0:        12 + 15i
Custom formatting with J3:        12.100 + 15.400j



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ValidationResult结构体代码示例发布时间:2022-05-26
下一篇:
C# BigInteger结构体代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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