This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 7cb883c54b787f93a400eb0b41cc486acf79164e
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Wed Aug 18 23:00:12 2021 +0100

    sonar fix: avoid division by zero in atan2 when y=0
---
 .../apache/commons/math4/legacy/core/jdkmath/AccurateMath.java | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git 
a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
 
b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
index a65b3c7..ee3e11d 100644
--- 
a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
+++ 
b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
@@ -2687,9 +2687,7 @@ public final class AccurateMath {
         }
 
         if (y == 0) {
-            final double result = x * y;
             final double invx = 1d / x;
-            final double invy = 1d / y;
 
             if (invx == 0) { // X is infinite
                 if (x > 0) {
@@ -2700,13 +2698,9 @@ public final class AccurateMath {
             }
 
             if (x < 0 || invx < 0) {
-                if (y < 0 || invy < 0) {
-                    return -Math.PI;
-                } else {
-                    return Math.PI;
-                }
+                return copySign(Math.PI, y);
             } else {
-                return result;
+                return x * y;
             }
         }
 

Reply via email to