Ejemplo n.º 1
0
 public boolean equals(Object obj) {
   if (obj == null || !(obj instanceof Complex)) return false;
   Complex y = (Complex) obj;
   return y.unit() == Unit.Empty
       && (Double.doubleToLongBits(real) == Double.doubleToLongBits(y.reValue()))
       && (Double.doubleToLongBits(imag) == Double.doubleToLongBits(y.imValue()));
 }
Ejemplo n.º 2
0
 public Numeric add(Object y, int k) {
   if (y instanceof Complex) {
     Complex yc = (Complex) y;
     if (yc.dimensions() != Dimensions.Empty) throw new ArithmeticException("units mis-match");
     return new DComplex(real + k * yc.reValue(), imag + k * yc.imValue());
   }
   return ((Numeric) y).addReversed(this, k);
 }
Ejemplo n.º 3
0
 public Numeric mul(Object y) {
   if (y instanceof Complex) {
     Complex yc = (Complex) y;
     if (yc.unit() == Unit.Empty) {
       double y_re = yc.reValue();
       double y_im = yc.imValue();
       return new DComplex(real * y_re - imag * y_im, real * y_im + imag * y_re);
     }
     return Complex.times(this, yc);
   }
   return ((Numeric) y).mulReversed(this);
 }