sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Replace usage of Math.nextUp(double) by Math.nextDown(double) where appropriate.
Date Mon, 03 Sep 2018 16:56:08 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 79f4643e79aedbe142019d84419d758e3e5b66ca
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Sep 3 18:26:04 2018 +0200

    Replace usage of Math.nextUp(double) by Math.nextDown(double) where appropriate.
---
 .../projection/ConformalProjectionTest.java        |  2 +-
 .../projection/LambertConicConformalTest.java      | 36 +++++++++++-----------
 .../operation/projection/MercatorTest.java         |  8 ++---
 .../java/org/apache/sis/measure/NumberRange.java   | 13 +++-----
 4 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/ConformalProjectionTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/ConformalProjectionTest.java
index ac1c2e3..010a944 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/ConformalProjectionTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/ConformalProjectionTest.java
@@ -64,7 +64,7 @@ public final strictfp class ConformalProjectionTest extends TransformTestCase
{
         assertEquals("Forward 0°N",      0, log(tan(PI/4)),                   TOLERANCE);
         assertEquals("Inverse 0 m",      0, PI/2 - 2*atan(exp(0)),            TOLERANCE);
         assertEquals("Forward 90°S",     NEGATIVE_INFINITY, log(tan(0)),      TOLERANCE);
-        assertEquals("Forward (90+ε)°S", NaN,  log(tan(-nextUp(0))),          TOLERANCE);
+        assertEquals("Forward (90+ε)°S", NaN,  log(tan(nextDown(0))),         TOLERANCE);
         assertEquals("Inverse −∞",       PI/2, atan(exp(-NEGATIVE_INFINITY)), TOLERANCE);
         assertEquals("Inverse −∞ appr.", PI/2, atan(exp(LN_INFINITY + 1)),    TOLERANCE);
         /*
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/LambertConicConformalTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/LambertConicConformalTest.java
index 0b029e1..143ec65 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/LambertConicConformalTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/LambertConicConformalTest.java
@@ -120,15 +120,15 @@ public final strictfp class LambertConicConformalTest extends MapProjectionTestC
             createNormalizedProjection(true, 40);       // Elliptical case
         }
         final double INF = POSITIVE_INFINITY;
-        assertEquals ("Not a number",     NaN, transform(NaN),            NORMALIZED_TOLERANCE);
-        assertEquals ("Out of range",     NaN, transform(+2),             NORMALIZED_TOLERANCE);
-        assertEquals ("Out of range",     NaN, transform(-2),             NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 0°N",      1,   transform(0),              NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 90°S",     0,   transform(-PI/2),          NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 90°N",     INF, transform(+PI/2),          NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90+ε)°S", 0,   transform(-nextUp( PI/2)), NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90+ε)°N", INF, transform(+nextUp(+PI/2)), NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90-ε)°S", 0,   transform(+nextUp(-PI/2)), 1E-10);
+        assertEquals ("Not a number",     NaN, transform(NaN),             NORMALIZED_TOLERANCE);
+        assertEquals ("Out of range",     NaN, transform(+2),              NORMALIZED_TOLERANCE);
+        assertEquals ("Out of range",     NaN, transform(-2),              NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 0°N",      1,   transform(0),               NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 90°S",     0,   transform(-PI/2),           NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 90°N",     INF, transform(+PI/2),           NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90+ε)°S", 0,   transform(nextDown(-PI/2)), NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90+ε)°N", INF, transform(nextUp  (+PI/2)), NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90-ε)°S", 0,   transform(nextUp  (-PI/2)), 1E-10);
 
         assertEquals ("Not a number", NaN, inverseTransform(NaN),  NORMALIZED_TOLERANCE);
         assertEquals ("Inverse 0",  -PI/2, inverseTransform( 0),   NORMALIZED_TOLERANCE);
@@ -141,15 +141,15 @@ public final strictfp class LambertConicConformalTest extends MapProjectionTestC
         createNormalizedProjection(((LambertConicConformal) transform).eccentricity != 0,
-40);
         validate();
 
-        assertEquals ("Not a number",     NaN, transform(NaN),            NORMALIZED_TOLERANCE);
-        assertEquals ("Out of range",     NaN, transform(+2),             NORMALIZED_TOLERANCE);
-        assertEquals ("Out of range",     NaN, transform(-2),             NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 0°N",      1,   transform(0),              NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 90°N",     INF, transform(+PI/2),          NORMALIZED_TOLERANCE);
-        assertEquals ("Forward 90°S",     0,   transform(-PI/2),          NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90+ε)°N", INF, transform(+nextUp(+PI/2)), NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90+ε)°S", 0,   transform(-nextUp( PI/2)), NORMALIZED_TOLERANCE);
-        assertEquals ("Forward (90-ε)°S", 0,   transform( nextUp(-PI/2)), 1E-10);
+        assertEquals ("Not a number",     NaN, transform(NaN),             NORMALIZED_TOLERANCE);
+        assertEquals ("Out of range",     NaN, transform(+2),              NORMALIZED_TOLERANCE);
+        assertEquals ("Out of range",     NaN, transform(-2),              NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 0°N",      1,   transform(0),               NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 90°N",     INF, transform(+PI/2),           NORMALIZED_TOLERANCE);
+        assertEquals ("Forward 90°S",     0,   transform(-PI/2),           NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90+ε)°N", INF, transform(nextUp  (+PI/2)), NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90+ε)°S", 0,   transform(nextDown(-PI/2)), NORMALIZED_TOLERANCE);
+        assertEquals ("Forward (90-ε)°S", 0,   transform(nextUp  (-PI/2)), 1E-10);
 
         assertEquals ("Not a number", NaN, inverseTransform(NaN),  NORMALIZED_TOLERANCE);
         assertEquals ("Inverse 0",  -PI/2, inverseTransform( 0),   NORMALIZED_TOLERANCE);
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
index 23d28aa..451e99a 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
@@ -141,10 +141,10 @@ public final strictfp class MercatorTest extends MapProjectionTestCase
{
         assertEquals ("Forward 0°N",      0,                      transform(0),        
    tolerance);
         assertEquals ("Forward 90°N",     POSITIVE_INFINITY,      transform(+PI/2),    
    tolerance);
         assertEquals ("Forward 90°S",     NEGATIVE_INFINITY,      transform(-PI/2),    
    tolerance);
-        assertEquals ("Forward (90+ε)°N", POSITIVE_INFINITY,      transform(+nextUp(PI/2)),
tolerance);
-        assertEquals ("Forward (90+ε)°S", NEGATIVE_INFINITY,      transform(-nextUp(PI/2)),
tolerance);
-        assertBetween("Forward (90-ε)°N", +MIN_VALUE, +MAX_VALUE, transform(-nextUp(-PI/2)));
-        assertBetween("Forward (90-ε)°S", -MAX_VALUE, -MIN_VALUE, transform(+nextUp(-PI/2)));
+        assertEquals ("Forward (90+ε)°N", POSITIVE_INFINITY,      transform(nextUp  ( PI/2)),
tolerance);
+        assertEquals ("Forward (90+ε)°S", NEGATIVE_INFINITY,      transform(nextDown(-PI/2)),
tolerance);
+        assertBetween("Forward (90-ε)°N", +MIN_VALUE, +MAX_VALUE, transform(nextDown( PI/2)));
+        assertBetween("Forward (90-ε)°S", -MAX_VALUE, -MIN_VALUE, transform(nextUp  (-PI/2)));
 
         assertEquals ("Not a number",     NaN,   inverseTransform(NaN),                tolerance);
         assertEquals ("Inverse 0 m",      0,     inverseTransform(0),                  tolerance);
diff --git a/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java b/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
index 968453c..6d1e207 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
@@ -513,23 +513,18 @@ public class NumberRange<E extends Number & Comparable<? super
E>> extends Range
      * @return the adjacent value.
      */
     private static double next(final Class<?> type, double value, final boolean up)
{
-        if (!up) {
-            value = -value;
-        }
         if (Numbers.isInteger(type)) {
-            value++;
+            if (up) value++; else value--;
         } else if (type.equals(Float.class)) {
-            value = Math.nextUp((float) value);
+            final float fv = (float) value;
+            value = up ? Math.nextUp(fv) : Math.nextDown(fv);
         } else if (type.equals(Double.class)) {
-            value = Math.nextUp(value);
+            value = up ? Math.nextUp(value) : Math.nextDown(value);
         } else {
             // Thrown IllegalStateException instead than IllegalArgumentException because
             // the 'type' argument given to this method come from a NumberRange field.
             throw new IllegalStateException(Errors.format(Errors.Keys.NotAPrimitiveWrapper_1,
type));
         }
-        if (!up) {
-            value = -value;
-        }
         return value;
     }
 


Mime
View raw message