/** |
* 复数的除法运算。 |
* c = a / b 的运算法则是: |
* c.实部 = (a.实部 * b.实部 + a.虚部 * b.虚部) / (b.实部 *b.实部 + b.虚部 * b.虚部); |
* c.虚部 = (a.虚部 * b.实部 - a.实部 * b.虚部) / (b.实部 * b.实部 + b.虚部 * b.虚部); |
* @param aComNum 除数 |
* @return |
*/ |
public ComplexNumber divide(ComplexNumber aComNum) { |
if (aComNum == null ) { |
System.err.println( "对象不能够为null!" ); |
return new ComplexNumber(); |
} |
if ((aComNum.getRealPart() == 0 ) && (aComNum.getImaginaryPart() == 0 )) { |
System.err.println( "除数不能够为0!" ); |
return new ComplexNumber(); |
} |
double temp = aComNum.getRealPart() * aComNum.getRealPart() |
+ aComNum.getImaginaryPart() * aComNum.getImaginaryPart(); |
double crealpart = ( this .realPart * aComNum.getRealPart() + this .imaginaryPart |
* aComNum.getImaginaryPart()) |
/ temp; |
double cimaginaryPart = ( this .imaginaryPart * aComNum.getRealPart() - this .realPart |
* aComNum.getImaginaryPart()) |
/ temp; |
return new ComplexNumber(crealpart, cimaginaryPart); |
} |