Fix complex square root for zero (#36266)
Contributed by: Xiaogang Zhang git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@239949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
69d29afc48
commit
b494c9f537
|
@ -216,12 +216,15 @@ public class ComplexUtils {
|
|||
|
||||
double a = z.getReal();
|
||||
double b = z.getImaginary();
|
||||
if (a == 0.0 && b == 0.0) {
|
||||
return new Complex(0.0, 0.0);
|
||||
}
|
||||
|
||||
double t = Math.sqrt((Math.abs(a) + z.abs()) / 2.0);
|
||||
if (a >= 0.0) {
|
||||
return new Complex(t, b / (2.0 * t));
|
||||
} else {
|
||||
return new Complex(Math.abs(z.getImaginary()) / (2.0 * t),
|
||||
return new Complex(Math.abs(b) / (2.0 * t),
|
||||
MathUtils.indicator(b) * t);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue