/*
 * Decompiled with CFR 0_132.
 */
package DFT;

import DFT.Phasor;

public class Complex {
    private float R;
    private float I;

    public Complex() {
        this.R = 0.0f;
        this.I = 0.0f;
    }

    public Complex(float r, float i) {
        this.R = r;
        this.I = i;
    }

    public Complex(Phasor ph) {
        this.R = ph.cx().R;
        this.I = ph.cx().I;
    }

    public void real(float r) {
        this.R = r;
    }

    public float real() {
        return this.R;
    }

    public void imag(float i) {
        this.I = i;
    }

    public float imag() {
        return this.I;
    }

    public float mag() {
        float Mag = (float)Math.sqrt(this.R * this.R + this.I * this.I);
        return Mag;
    }

    public float angle() {
        float Angle = (float)Math.atan(this.I / this.R);
        Angle = Angle * 180.0f / 3.1415927f;
        return Angle;
    }

    public Phasor phase() {
        Phasor ph = new Phasor(this.mag(), this.angle());
        return ph;
    }

    public Complex add(Complex rhs) {
        float newR = this.R + rhs.R;
        float newI = this.I + rhs.I;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public Complex sub(Complex rhs) {
        float newR = this.R - rhs.R;
        float newI = this.I - rhs.I;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public Complex mult(Complex rhs) {
        float newR = this.R * rhs.R - this.I * rhs.I;
        float newI = this.R * rhs.I + rhs.R * this.I;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public Complex mult(float rhs) {
        float newR = this.R * rhs;
        float newI = rhs * this.I;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public Complex div(Complex divisor) {
        float R2 = divisor.R;
        float I2 = divisor.I;
        float div = R2 * R2 + I2 * I2;
        float newR = (this.R * R2 + this.I * I2) / div;
        float newI = (R2 * this.I - this.R * I2) / div;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public Complex div(float divisor) {
        float R2 = divisor;
        float I2 = 0.0f;
        float div = R2 * R2;
        float newR = this.R * R2 / div;
        float newI = R2 * this.I / div;
        Complex C = new Complex(newR, newI);
        return C;
    }

    public boolean eq(Complex rhs) {
        if (this.R == rhs.R && this.I == rhs.I) {
            return true;
        }
        return false;
    }
}

