@Override public IComplexNumber exp() { IComplexNumber result = dup(); double realExp = FastMath.exp(realComponent()); return result.set( realExp * FastMath.cos(imaginaryComponent()), realExp * FastMath.sin(imaginaryComponent())); }
@Override public IComplexNumber powi(IComplexNumber c, IComplexNumber result) { IComplexNumber eval = log().muli(c).exp(); result.set(eval.realComponent(), eval.imaginaryComponent()); result.set(eval.realComponent(), eval.imaginaryComponent()); return result; }
@Override public IComplexNumber divi(Number v, IComplexNumber result) { if (this == result) { set(real() / v.doubleValue(), imag()); } else { result.set(result.realComponent().doubleValue() / v.doubleValue(), imaginaryComponent()); } return result; }
/** * Multiply two complex numbers, inplace * * @param c * @param result */ @Override public IComplexNumber muli(IComplexNumber c, IComplexNumber result) { double newR = (real() * c.realComponent().doubleValue() - imag() * c.imaginaryComponent().doubleValue()); double newI = (real() * c.imaginaryComponent().doubleValue() + imag() * c.realComponent().doubleValue()); result.set(newR, newI); return result; }
@Override public IComplexNumber rdivi(Number v, IComplexNumber result) { float d = result.realComponent().floatValue() * result.realComponent().floatValue() + result.imaginaryComponent().floatValue() * result.imaginaryComponent().floatValue(); return result.set( v.floatValue() * result.realComponent().floatValue() / d, -v.floatValue() * result.imaginaryComponent().floatValue() / d); }
/** * Multiply two complex numbers, inplace * * @param c * @param result */ @Override public IComplexNumber muli(IComplexNumber c, IComplexNumber result) { float newR = real() * c.realComponent().floatValue() - imag() * c.imaginaryComponent().floatValue(); float newI = real() * c.imaginaryComponent().floatValue() + imag() * c.realComponent().floatValue(); result.set(newR, newI); return result; }
@Override public IComplexNumber log() { IComplexNumber result = dup(); float real = (float) result.realComponent(); float imaginary = (float) result.imaginaryComponent(); double modulus = FastMath.sqrt(real * real + imaginary * imaginary); double arg = FastMath.atan2(imaginary, real); return result.set(FastMath.log(modulus), arg); }
/** * Subtract two complex numbers, in-place * * @param c * @param result */ @Override public IComplexNumber subi(IComplexNumber c, IComplexNumber result) { if (this == result) { set(real() - c.realComponent().doubleValue(), imag() - c.imaginaryComponent().doubleValue()); } else { result.set( result.realComponent().doubleValue() - c.realComponent().doubleValue(), result.imaginaryComponent().doubleValue() - c.imaginaryComponent().doubleValue()); } return this; }
/** * Divide two complex numbers, in-place * * @param c * @param result */ @Override public IComplexNumber divi(IComplexNumber c, IComplexNumber result) { float d = c.realComponent().floatValue() * c.realComponent().floatValue() + c.imaginaryComponent().floatValue() * c.imaginaryComponent().floatValue(); float newR = (real() * c.realComponent().floatValue() + imag() * c.imaginaryComponent().floatValue()) / d; float newI = (imag() * c.realComponent().floatValue() - real() * c.imaginaryComponent().floatValue()) / d; result.set(newR, newI); return result; }
@Override public IComplexNumber rsubi(Number a, IComplexNumber result) { return result.set(a.doubleValue() - realComponent().doubleValue(), imaginaryComponent()); }
@Override public IComplexNumber copy(IComplexNumber other) { return other.set(this); }
@Override public IComplexNumber rsubi(IComplexNumber a, IComplexNumber result) { return result.set(a.sub(this)); }
@Override public IComplexNumber subi(Number a, IComplexNumber result) { return result.set( result.realComponent().floatValue() - a.floatValue(), result.imaginaryComponent().floatValue()); }
@Override public IComplexNumber divi(Number v, IComplexNumber result) { return result.set( result.realComponent().floatValue() / v.floatValue(), imaginaryComponent() / v.floatValue()); }
@Override public IComplexNumber rdivi(IComplexNumber c, IComplexNumber result) { return result.set(c.div(this)); }
@Override public IComplexNumber rdivi(Number v, IComplexNumber result) { return result.set(v.doubleValue() / real(), imaginaryComponent()); }
/** * Add two complex numbers in-place * * @param c * @param result */ @Override public IComplexNumber addi(IComplexNumber c, IComplexNumber result) { return result.set( result.realComponent().floatValue() + c.realComponent().floatValue(), result.imaginaryComponent().floatValue() + c.imaginaryComponent().floatValue()); }