Der Datentyp Complex

package fft;

class Complex {

    private   double real;
    private   double img;

    Complex(double real, double imaginary) {
   this.real = real;
   img = imaginary;
    }

    public String toString() {
   return real + " + " + img + "i" ;
    }
    
    /* Complex.add(x, y) */
    static Complex add(Complex a, Complex b) {

   return new Complex(a.real + b.real, a.img + b.img);

    }

    /* x.add(y) */
    Complex add(Complex other) {
   //real = real + other.real;
   //img  += other.img;
   //return this;

   return new Complex( real + other.real, img + other.img);
    }
    
    static Complex multiply(Complex x, Complex y) {
   return new Complex(x.real * y.real - x.img * y.img, 
            x.real * y.img + x.img * y.real);
    }
    
    /* x**n */
    static Complex exp(Complex x, int n) {
   if (n == 0) {
       return new Complex(1,0);
   } else {
       return Complex.multiply(x, Complex.exp(x, --n));
   }
    }

    /* = cos(2pi/n) + i(sin(2pi/n))
     */
    static Complex getRootOfUnity(int n){
   return new Complex(Math.cos(2 * Math.PI /n), Math.sin(2 * Math.PI /n));
    }
    
}

-- Christo - 12 Dec 2003
Topic revision: r1 - 2003-12-12, ChristopherHuhn - This page was cached on 2024-11-20 - 02:40.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)