Ejemplo n.º 1
0
        // --------------SECTION: Other arithmetic operations  -------------- //

        public static Double Abs(Comlexnumber value)
        {
            if (Double.IsInfinity(value.real) || Double.IsInfinity(value.imaginary))
            {
                return(double.PositiveInfinity);
            }


            double c = Math.Abs(value.real);
            double d = Math.Abs(value.imaginary);

            if (c > d)
            {
                double r = d / c;
                return(c * Math.Sqrt(1.0 + r * r));
            }
            else if (d == 0.0)
            {
                return(c);  // c is either 0.0 or NaN
            }
            else
            {
                double r = c / d;
                return(d * Math.Sqrt(1.0 + r * r));
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter real part of complex number");
            var real = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter imaginary part of complex number");
            var          imaginary  = double.Parse(Console.ReadLine());
            Comlexnumber newcomplex = new Comlexnumber(real, imaginary);

            Console.WriteLine("newcomplex:  {0}", newcomplex);


            double phase = newcomplex.Phase;

            Console.WriteLine("newcomplex-phase:  {0}", phase);

            Comlexnumber val1 = new Comlexnumber(1, 1);
            Comlexnumber val2 = new Comlexnumber(2, 6);

            Console.WriteLine("First:  {0}", val1);
            Console.WriteLine("Second: {0}", val2);

            // Add both of them
            Comlexnumber res = val1 + val2;

            Console.WriteLine("Result (Sum): {0}", res);
            res = Comlexnumber.Add(val1, val2);

            Console.WriteLine("Result (Sum-1): {0}", res);
            //Multiply

            res = val1 * val2;
            Console.WriteLine("Result (Multiplay): {0}", res);
            res = Comlexnumber.Multiply(val1, val2);
            Console.WriteLine("Result (Multiplay-1): {0}", res);
            //Divide

            res = val1 / val2;
            Console.WriteLine("Result (Division): {0}", res);
            res = Comlexnumber.Divide(val1, val2);
            Console.WriteLine("Result (Division-1): {0}", res);
            //ABS
            double res1 = Comlexnumber.Abs(val1);

            Console.WriteLine("Result (ABS-res): {0}", res1);

            Console.WriteLine("Equal to Magnitude: {0}",

                              Comlexnumber.Abs(val1).Equals(val1.Magnitude));

            //Subtract
            res = val1 - val2;
            Console.WriteLine("Result (Subtract): {0}", res);
            res = Comlexnumber.Subtract(val1, val2);
            Console.WriteLine("Result (Subtract-1): {0}", res);
            //Negate

            res = -val1;
            Console.WriteLine("Result (Negate): {0}", res);
            res = Comlexnumber.Negate(val1);
            Console.WriteLine("Result (Negate-1): {0}", res);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
 public static Comlexnumber Divide(Comlexnumber dividend, Comlexnumber divisor)
 {
     return(dividend / divisor);
 }
Ejemplo n.º 4
0
 public static Comlexnumber Multiply(Comlexnumber firts, Comlexnumber second)
 {
     return(firts * second);
 }
Ejemplo n.º 5
0
 public static Comlexnumber Subtract(Comlexnumber firts, Comlexnumber second)
 {
     return(firts - second);
 }
Ejemplo n.º 6
0
 public static Comlexnumber Add(Comlexnumber firts, Comlexnumber second)
 {
     return(firts + second);
 }
Ejemplo n.º 7
0
        // --------------SECTION: Constructors and factory methods -------------- //



        public static Comlexnumber Negate(Comlexnumber value)
        {
            return(-value);
        }