Removed dead code, improved test coverage. Dead code pointed out in JIRA: MATH-306. Thanks to Joerg Huber.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@830044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2009-10-27 01:32:19 +00:00
parent cdfddcc20a
commit c09247c09b
3 changed files with 23 additions and 7 deletions

View File

@ -177,7 +177,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
* <pre><code>
* a + bi ac + bd + (bc - ad)i
* ----------- = -------------------------
* c + di c<sup>2</sup> + d<sup>2</sup>
* c + di c<sup>2</sup> + d<sup>2</sup>
* </code></pre>
* but uses
* <a href="http://doi.acm.org/10.1145/1039813.1039814">
@ -221,17 +221,11 @@ public class Complex implements FieldElement<Complex>, Serializable {
}
if (Math.abs(c) < Math.abs(d)) {
if (d == 0.0) {
return createComplex(real/c, imaginary/c);
}
double q = c / d;
double denominator = c * q + d;
return createComplex((real * q + imaginary) / denominator,
(imaginary * q - real) / denominator);
} else {
if (c == 0.0) {
return createComplex(imaginary/d, -real/c);
}
double q = d / c;
double denominator = d * q + c;
return createComplex((imaginary * q + real) / denominator,

View File

@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="2.1" date="TBD" description="TBD">
<action dev="psteitz" type="fix" issue="MATH-306" due-to="Joerg Huber">
Removed dead code from Complex#divide.
</action>
<action dev="psteitz" tyoe="fix" issue="MATH-294">
Fixed implementation of RandomDataImpl#nextPoisson by implementing an alternative
algorithm for large means.

View File

@ -144,6 +144,19 @@ public class ComplexTest extends TestCase {
assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5);
assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
}
public void testDivideReal() {
Complex x = new Complex(2d, 3d);
Complex y = new Complex(2d, 0d);
assertEquals(new Complex(1d, 1.5), x.divide(y));
}
public void testDivideImaginary() {
Complex x = new Complex(2d, 3d);
Complex y = new Complex(0d, 2d);
assertEquals(new Complex(1.5d, -1d), x.divide(y));
}
public void testDivideInfinite() {
Complex x = new Complex(3, 4);
@ -164,6 +177,12 @@ public class ComplexTest extends TestCase {
assertTrue(Double.isNaN(z.getReal()));
assertTrue(Double.isNaN(z.getImaginary()));
}
public void testDivideZero() {
Complex x = new Complex(3.0, 4.0);
Complex z = x.divide(Complex.ZERO);
assertEquals(z, Complex.NaN);
}
public void testDivideNaN() {
Complex x = new Complex(3.0, 4.0);