sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/04: Use Math.IEEEremainder(…) when we know that minimum == -maximum.
Date Tue, 12 Feb 2019 15:50:43 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit b4a4fde6cb2b3e6a6bd3321aff19af0bb4ef0893
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Feb 12 12:25:49 2019 +0100

    Use Math.IEEEremainder(…) when we know that minimum == -maximum.
---
 .../src/main/java/org/apache/sis/measure/Longitude.java  | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java b/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
index 67c85a0..97eeca4 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
@@ -148,7 +148,19 @@ public final class Longitude extends Angle {
      *
      * @since 0.4
      */
-    public static double normalize(final double λ) {
-        return λ - Math.floor((λ - MIN_VALUE) / (MAX_VALUE - MIN_VALUE)) * (MAX_VALUE -
MIN_VALUE);
+    public static double normalize(double λ) {
+        /*
+         * Following should be simplified as only one branch by javac since
+         * the values used in the 'if' statement are compile-time constants.
+         * For verifying: javap -c org.apache.sis.measure.Longitude
+         */
+        if (MIN_VALUE == -MAX_VALUE) {
+            λ = Math.IEEEremainder(λ, MAX_VALUE - MIN_VALUE);
+            if (λ == MAX_VALUE) λ = MIN_VALUE;
+            return λ;
+        } else {
+            // Normally excluded from compiled file, but defined in case someone modifies
MIN/MAX_VALUE.
+            return λ - Math.floor((λ - MIN_VALUE) / (MAX_VALUE - MIN_VALUE)) * (MAX_VALUE
- MIN_VALUE);
+        }
     }
 }


Mime
View raw message