You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/18 22:16:04 UTC
[commons-math] branch master updated: Simplify atan2 expressions
when y is non-zero
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
The following commit(s) were added to refs/heads/master by this push:
new 56b7b12 Simplify atan2 expressions when y is non-zero
56b7b12 is described below
commit 56b7b12c2a90afc4bdcc7658c9173d8c7ef064ea
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Aug 18 23:16:01 2021 +0100
Simplify atan2 expressions when y is non-zero
---
.../math4/legacy/core/jdkmath/AccurateMath.java | 30 ++++------------------
1 file changed, 5 insertions(+), 25 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 ee3e11d..88d1537 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
@@ -2692,16 +2692,14 @@ public final class AccurateMath {
if (invx == 0) { // X is infinite
if (x > 0) {
return y; // return +/- 0.0
- } else {
- return copySign(Math.PI, y);
}
+ return copySign(Math.PI, y);
}
if (x < 0 || invx < 0) {
return copySign(Math.PI, y);
- } else {
- return x * y;
}
+ return x * y;
}
// y cannot now be zero
@@ -2731,35 +2729,17 @@ public final class AccurateMath {
}
if (x == Double.POSITIVE_INFINITY) {
- if (y > 0 || 1 / y > 0) {
- return 0d;
- }
-
- if (y < 0 || 1 / y < 0) {
- return -0d;
- }
+ return y > 0 ? 0d : -0d;
}
if (x == Double.NEGATIVE_INFINITY) {
- if (y > 0.0 || 1 / y > 0.0) {
- return Math.PI;
- }
-
- if (y < 0 || 1 / y < 0) {
- return -Math.PI;
- }
+ return y > 0 ? Math.PI : -Math.PI;
}
// Neither y nor x can be infinite or NAN here
if (x == 0) {
- if (y > 0 || 1 / y > 0) {
- return Math.PI * F_1_2;
- }
-
- if (y < 0 || 1 / y < 0) {
- return -Math.PI * F_1_2;
- }
+ return y > 0 ? Math.PI * F_1_2 : -Math.PI * F_1_2;
}
// Compute ratio r = y/x