mirror of
https://github.com/apache/commons-math.git
synced 2025-02-08 11:05:56 +00:00
Made scalar division consistent with complex division wrt infinite arguments, improved tests.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1150433 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
093aa6786f
commit
431ff783f0
@ -278,13 +278,12 @@ public class Complex implements FieldElement<Complex>, Serializable {
|
||||
if (isNaN || Double.isNaN(divisor)) {
|
||||
return NaN;
|
||||
}
|
||||
if (divisor == 0.0) {
|
||||
if (divisor == 0d) {
|
||||
return NaN;
|
||||
}
|
||||
if (Double.isInfinite(divisor) && !isInfinite()) {
|
||||
return ZERO;
|
||||
if (Double.isInfinite(divisor)) {
|
||||
return !isInfinite() ? ZERO : NaN;
|
||||
}
|
||||
|
||||
return createComplex(real / divisor,
|
||||
imaginary / divisor);
|
||||
}
|
||||
|
@ -274,11 +274,20 @@ public class ComplexTest {
|
||||
Complex x = new Complex(1,1);
|
||||
double yDouble = Double.POSITIVE_INFINITY;
|
||||
Complex yComplex = new Complex(yDouble);
|
||||
Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
|
||||
TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
|
||||
|
||||
yDouble = Double.NEGATIVE_INFINITY;
|
||||
yComplex = new Complex(yDouble);
|
||||
Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
|
||||
TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
|
||||
|
||||
x = new Complex(1, Double.NEGATIVE_INFINITY);
|
||||
TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScalarDivideZero() {
|
||||
Complex x = new Complex(1,1);
|
||||
TestUtils.assertEquals(x.divide(Complex.ZERO), x.divide(0), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user