package org.nfunk.jep.type;

public class Complex {
  private double re = 0.0D;
  
  private double im = 0.0D;
  
  public Complex() {}
  
  public Complex(double paramDouble) {}
  
  public Complex(Number paramNumber) {}
  
  public Complex(Complex paramComplex) {}
  
  public Complex(double paramDouble1, double paramDouble2) {}
  
  public double re() {
    return this.re;
  }
  
  public double im() {
    return this.im;
  }
  
  public void set(Complex paramComplex) {
    this.re = paramComplex.re;
    this.im = paramComplex.im;
  }
  
  public void set(double paramDouble1, double paramDouble2) {
    this.re = paramDouble1;
    this.im = paramDouble2;
  }
  
  public void setRe(double paramDouble) {
    this.re = paramDouble;
  }
  
  public void setIm(double paramDouble) {
    this.im = paramDouble;
  }
  
  public boolean equals(Complex paramComplex, double paramDouble) {
    double d1 = this.re - paramComplex.re;
    double d2 = this.im - paramComplex.im;
    return (d1 * d1 + d2 * d2 <= paramDouble * paramDouble);
  }
  
  public boolean equals(Object paramObject) {
    if (!(paramObject instanceof Complex))
      return false; 
    Complex complex = (Complex)paramObject;
    return (Double.doubleToLongBits(this.re) == Double.doubleToLongBits(complex.re) && Double.doubleToLongBits(this.im) == Double.doubleToLongBits(complex.im));
  }
  
  public int hashCode() {
    null = 17;
    long l1 = Double.doubleToLongBits(this.re);
    long l2 = Double.doubleToLongBits(this.im);
    int i = (int)(l1 ^ l1 >> 32L);
    int j = (int)(l2 ^ l2 >> 32L);
    null = 37 * null + i;
    return 37 * null + j;
  }
  
  public String toString() {
    return "(" + this.re + ", " + this.im + ")";
  }
  
  public boolean isInfinite() {
    return (Double.isInfinite(this.re) || Double.isInfinite(this.im));
  }
  
  public boolean isNaN() {
    return (Double.isNaN(this.re) || Double.isNaN(this.im));
  }
  
  public double abs() {
    double d1 = Math.abs(this.re);
    double d2 = Math.abs(this.im);
    if (d1 == 0.0D && d2 == 0.0D)
      return 0.0D; 
    if (d1 > d2) {
      double d = d2 / d1;
      return d1 * Math.sqrt(1.0D + d * d);
    } 
    double d3 = d1 / d2;
    return d2 * Math.sqrt(1.0D + d3 * d3);
  }
  
  public double abs2() {
    return this.re * this.re + this.im * this.im;
  }
  
  public double arg() {
    return Math.atan2(this.im, this.re);
  }
  
  public Complex neg() {
    return new Complex(-this.re, -this.im);
  }
  
  public Complex mul(double paramDouble) {
    return new Complex(this.re * paramDouble, this.im * paramDouble);
  }
  
  public Complex add(Complex paramComplex) {
    return new Complex(this.re + paramComplex.re, this.im + paramComplex.im);
  }
  
  public Complex sub(Complex paramComplex) {
    return new Complex(this.re - paramComplex.re, this.im - paramComplex.im);
  }
  
  public Complex mul(Complex paramComplex) {
    return new Complex(this.re * paramComplex.re - this.im * paramComplex.im, this.im * paramComplex.re + this.re * paramComplex.im);
  }
  
  public Complex div(Complex paramComplex) {
    double d1;
    double d2;
    if (Math.abs(paramComplex.re) >= Math.abs(paramComplex.im)) {
      double d3 = paramComplex.im / paramComplex.re;
      double d4 = paramComplex.re + d3 * paramComplex.im;
      d1 = (this.re + d3 * this.im) / d4;
      d2 = (this.im - d3 * this.re) / d4;
    } else {
      double d3 = paramComplex.re / paramComplex.im;
      double d4 = paramComplex.im + d3 * paramComplex.re;
      d1 = (this.re * d3 + this.im) / d4;
      d2 = (this.im * d3 - this.re) / d4;
    } 
    return new Complex(d1, d2);
  }
  
  public Complex power(double paramDouble) {
    double d1 = Math.pow(abs(), paramDouble);
    boolean bool = false;
    byte b = 0;
    if (this.im == 0.0D && this.re < 0.0D) {
      bool = true;
      b = 2;
    } 
    if (this.re == 0.0D && this.im > 0.0D) {
      bool = true;
      b = 1;
    } 
    if (this.re == 0.0D && this.im < 0.0D) {
      bool = true;
      b = -1;
    } 
    if (bool && b * paramDouble == (int)(b * paramDouble)) {
      short[] arrayOfShort1 = { 0, 1, 0, -1 };
      short[] arrayOfShort2 = { 1, 0, -1, 0 };
      int i = (int)(b * paramDouble) % 4;
      if (i < 0)
        i = 4 + i; 
      return new Complex(d1 * arrayOfShort2[i], d1 * arrayOfShort1[i]);
    } 
    double d2 = paramDouble * arg();
    return new Complex(d1 * Math.cos(d2), d1 * Math.sin(d2));
  }
  
  public Complex power(Complex paramComplex) {
    if (paramComplex.im == 0.0D)
      return power(paramComplex.re); 
    double d1 = Math.log(abs());
    double d2 = arg();
    double d3 = d1 * paramComplex.re - d2 * paramComplex.im;
    double d4 = d1 * paramComplex.im + d2 * paramComplex.re;
    double d5 = Math.exp(d3);
    return new Complex(d5 * Math.cos(d4), d5 * Math.sin(d4));
  }
  
  public Complex log() {
    return new Complex(Math.log(abs()), arg());
  }
  
  public Complex sqrt() {
    Complex complex;
    if (this.re == 0.0D && this.im == 0.0D) {
      complex = new Complex(0.0D, 0.0D);
    } else {
      double d3;
      double d1 = Math.abs(this.re);
      double d2 = Math.abs(this.im);
      if (d1 >= d2) {
        double d = d2 / d1;
        d3 = Math.sqrt(d1) * Math.sqrt(0.5D * (1.0D + Math.sqrt(1.0D + d * d)));
      } else {
        double d = d1 / d2;
        d3 = Math.sqrt(d2) * Math.sqrt(0.5D * (d + Math.sqrt(1.0D + d * d)));
      } 
      if (this.re >= 0.0D) {
        complex = new Complex(d3, this.im / 2.0D * d3);
      } else {
        if (this.im < 0.0D)
          d3 = -d3; 
        complex = new Complex(this.im / 2.0D * d3, d3);
      } 
    } 
    return complex;
  }
  
  public Complex sin() {
    double d1 = -this.im;
    double d2 = this.re;
    double d7 = Math.exp(d1);
    double d3 = d7 * Math.cos(d2);
    double d4 = d7 * Math.sin(d2);
    d7 = Math.exp(-d1);
    double d5 = d7 * Math.cos(-d2);
    double d6 = d7 * Math.sin(-d2);
    d3 -= d5;
    d4 -= d6;
    return new Complex(0.5D * d4, -0.5D * d3);
  }
  
  public Complex cos() {
    double d1 = -this.im;
    double d2 = this.re;
    double d7 = Math.exp(d1);
    double d3 = d7 * Math.cos(d2);
    double d4 = d7 * Math.sin(d2);
    d7 = Math.exp(-d1);
    double d5 = d7 * Math.cos(-d2);
    double d6 = d7 * Math.sin(-d2);
    d3 += d5;
    d4 += d6;
    return new Complex(0.5D * d3, 0.5D * d4);
  }
  
  public Complex tan() {
    double d1 = -this.im;
    double d2 = this.re;
    double d7 = Math.exp(d1);
    double d3 = d7 * Math.cos(d2);
    double d4 = d7 * Math.sin(d2);
    d7 = Math.exp(-d1);
    double d5 = d7 * Math.cos(-d2);
    double d6 = d7 * Math.sin(-d2);
    d3 -= d5;
    d4 -= d6;
    Complex complex1 = new Complex(0.5D * d3, 0.5D * d4);
    d1 = -this.im;
    d2 = this.re;
    d7 = Math.exp(d1);
    d3 = d7 * Math.cos(d2);
    d4 = d7 * Math.sin(d2);
    d7 = Math.exp(-d1);
    d5 = d7 * Math.cos(-d2);
    d6 = d7 * Math.sin(-d2);
    d3 += d5;
    d4 += d6;
    Complex complex2 = new Complex(0.5D * d3, 0.5D * d4);
    return complex1.div(complex2);
  }
  
  public Complex asin() {
    double d1 = 1.0D - this.re * this.re - this.im * this.im;
    double d2 = 0.0D - this.re * this.im + this.im * this.re;
    Complex complex = new Complex(d1, d2);
    complex = complex.sqrt();
    complex.re += -this.im;
    complex.im += this.re;
    d1 = Math.log(complex.abs());
    d2 = complex.arg();
    complex.re = d2;
    complex.im = -d1;
    return complex;
  }
  
  public Complex acos() {
    double d1 = 1.0D - this.re * this.re - this.im * this.im;
    double d2 = 0.0D - this.re * this.im + this.im * this.re;
    Complex complex = new Complex(d1, d2);
    complex = complex.sqrt();
    d1 = -complex.im;
    d2 = complex.re;
    this.re += d1;
    this.im += d2;
    d1 = Math.log(complex.abs());
    d2 = complex.arg();
    complex.re = d2;
    complex.im = -d1;
    return complex;
  }
  
  public Complex atan() {
    Complex complex = new Complex(-this.re, 1.0D - this.im);
    double d1 = this.re;
    double d2 = 1.0D + this.im;
    complex = complex.div(new Complex(d1, d2));
    d1 = Math.log(complex.abs());
    d2 = complex.arg();
    complex.re = 0.5D * d2;
    complex.im = -0.5D * d1;
    return complex;
  }
  
  public Complex sinh() {
    double d1 = Math.exp(this.re);
    double d2 = d1 * Math.cos(this.im);
    double d3 = d1 * Math.sin(this.im);
    d1 = Math.exp(-this.re);
    double d4 = d1 * Math.cos(-this.im);
    double d5 = d1 * Math.sin(-this.im);
    d2 -= d4;
    d3 -= d5;
    return new Complex(0.5D * d2, 0.5D * d3);
  }
  
  public Complex cosh() {
    double d1 = Math.exp(this.re);
    double d2 = d1 * Math.cos(this.im);
    double d3 = d1 * Math.sin(this.im);
    d1 = Math.exp(-this.re);
    double d4 = d1 * Math.cos(-this.im);
    double d5 = d1 * Math.sin(-this.im);
    d2 += d4;
    d3 += d5;
    return new Complex(0.5D * d2, 0.5D * d3);
  }
  
  public Complex tanh() {
    double d1 = Math.exp(this.re);
    double d2 = d1 * Math.cos(this.im);
    double d3 = d1 * Math.sin(this.im);
    d1 = Math.exp(-this.re);
    double d4 = d1 * Math.cos(-this.im);
    double d5 = d1 * Math.sin(-this.im);
    d2 -= d4;
    d3 -= d5;
    Complex complex1 = new Complex(0.5D * d2, 0.5D * d3);
    d1 = Math.exp(this.re);
    d2 = d1 * Math.cos(this.im);
    d3 = d1 * Math.sin(this.im);
    d1 = Math.exp(-this.re);
    d4 = d1 * Math.cos(-this.im);
    d5 = d1 * Math.sin(-this.im);
    d2 += d4;
    d3 += d5;
    Complex complex2 = new Complex(0.5D * d2, 0.5D * d3);
    return complex1.div(complex2);
  }
  
  public Complex asinh() {
    Complex complex = new Complex(this.re * this.re - this.im * this.im + 1.0D, this.re * this.im + this.im * this.re);
    complex = complex.sqrt();
    complex.re += this.re;
    complex.im += this.im;
    double d = complex.arg();
    complex.re = Math.log(complex.abs());
    complex.im = d;
    return complex;
  }
  
  public Complex acosh() {
    Complex complex = new Complex(this.re * this.re - this.im * this.im - 1.0D, this.re * this.im + this.im * this.re);
    complex = complex.sqrt();
    complex.re += this.re;
    complex.im += this.im;
    double d = complex.arg();
    complex.re = Math.log(complex.abs());
    complex.im = d;
    return complex;
  }
  
  public Complex atanh() {
    Complex complex = new Complex(1.0D + this.re, this.im);
    double d1 = 1.0D - this.re;
    double d2 = -this.im;
    complex = complex.div(new Complex(d1, d2));
    d1 = Math.log(complex.abs());
    d2 = complex.arg();
    complex.re = 0.5D * d1;
    complex.im = 0.5D * d2;
    return complex;
  }
  
  public static Complex polarValueOf(Number paramNumber1, Number paramNumber2) {
    double d1 = paramNumber1.doubleValue();
    double d2 = paramNumber2.doubleValue();
    return new Complex(d1 * Math.cos(d2), d1 * Math.sin(d2));
  }
  
  public double doubleValue() {
    return this.re;
  }
  
  public float floatValue() {
    return (float)this.re;
  }
  
  public int intValue() {
    return (int)this.re;
  }
  
  public long longValue() {
    return (long)this.re;
  }
}
