All pastes #197852 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-10-11 15:48 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

namespace Buddhabrot
{
    public class Complex
    {

        private double _real;
        public double real
        { 
            get { return _real; } 
            set { _real = value; } 
        }

        private double _imaginary;
        public double imaginary
        {
            get { return _imaginary; }
            set { _imaginary = value; }
        }

        public Complex conjugate
        {
            get { return new Complex(real, Math.Abs(_imaginary)); }
        }

        public double absoluteValue
        {
            get { return magnitude; }
        }

        public double magnitude
        {
            get { return Math.Sqrt(this.square); }
        }

        private double square
        {
            get { return (_real * _real) + (_imaginary * _imaginary); }
        }

        public double length
        {
            get { return magnitude; }
        }

        public double theta
        {
            get { return Math.Tan(_imaginary / _real); }
        }

        public Complex clone
        {
            get { return new Complex(_real, _imaginary); }
        }

        public Complex(double nReal, double nImaginary)
        {
            _real = nReal;
            _imaginary = nImaginary;
        }

        public static Complex operator +(Complex c1, Complex c2)
        {
            return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
        }

        public static Complex operator -(Complex c1, Complex c2)
        {
            return new Complex(c1.real - c2.real, c1.imaginary - c2.imaginary);
        }

        public static Complex operator *(Complex c1, Complex c2)
        {
            return new Complex(c1.real * c2.real - c1.imaginary * c2.imaginary, c1.imaginary * c2.real + c1.real * c2.imaginary);
        }

        public static Complex operator /(Complex c1, Complex c2)
        {
            double denominator = c2.square;
            Complex c3 = c1 * c2;
            return new Complex(c3.real / denominator, c3.imaginary / denominator);
        }

        public override string ToString()
        {
            return (System.String.Format("{0} + {1}i", real, imaginary));
        }

    }
}