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:
parent
cdfddcc20a
commit
c09247c09b
|
@ -177,7 +177,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
|
||||||
* <pre><code>
|
* <pre><code>
|
||||||
* a + bi ac + bd + (bc - ad)i
|
* 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>
|
* </code></pre>
|
||||||
* but uses
|
* but uses
|
||||||
* <a href="http://doi.acm.org/10.1145/1039813.1039814">
|
* <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 (Math.abs(c) < Math.abs(d)) {
|
||||||
if (d == 0.0) {
|
|
||||||
return createComplex(real/c, imaginary/c);
|
|
||||||
}
|
|
||||||
double q = c / d;
|
double q = c / d;
|
||||||
double denominator = c * q + d;
|
double denominator = c * q + d;
|
||||||
return createComplex((real * q + imaginary) / denominator,
|
return createComplex((real * q + imaginary) / denominator,
|
||||||
(imaginary * q - real) / denominator);
|
(imaginary * q - real) / denominator);
|
||||||
} else {
|
} else {
|
||||||
if (c == 0.0) {
|
|
||||||
return createComplex(imaginary/d, -real/c);
|
|
||||||
}
|
|
||||||
double q = d / c;
|
double q = d / c;
|
||||||
double denominator = d * q + c;
|
double denominator = d * q + c;
|
||||||
return createComplex((imaginary * q + real) / denominator,
|
return createComplex((imaginary * q + real) / denominator,
|
||||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="2.1" date="TBD" description="TBD">
|
<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">
|
<action dev="psteitz" tyoe="fix" issue="MATH-294">
|
||||||
Fixed implementation of RandomDataImpl#nextPoisson by implementing an alternative
|
Fixed implementation of RandomDataImpl#nextPoisson by implementing an alternative
|
||||||
algorithm for large means.
|
algorithm for large means.
|
||||||
|
|
|
@ -145,6 +145,19 @@ public class ComplexTest extends TestCase {
|
||||||
assertEquals(2.0 / 61.0, z.getImaginary(), 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() {
|
public void testDivideInfinite() {
|
||||||
Complex x = new Complex(3, 4);
|
Complex x = new Complex(3, 4);
|
||||||
Complex w = new Complex(neginf, inf);
|
Complex w = new Complex(neginf, inf);
|
||||||
|
@ -165,6 +178,12 @@ public class ComplexTest extends TestCase {
|
||||||
assertTrue(Double.isNaN(z.getImaginary()));
|
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() {
|
public void testDivideNaN() {
|
||||||
Complex x = new Complex(3.0, 4.0);
|
Complex x = new Complex(3.0, 4.0);
|
||||||
Complex z = x.divide(Complex.NaN);
|
Complex z = x.divide(Complex.NaN);
|
||||||
|
|
Loading…
Reference in New Issue