[PATCH 1 of 2] Fixed: rounding methods NaN aware in Formatter

Wald Commits scm-commit at wald.intevation.org
Thu Aug 2 16:11:27 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1533218931 -7200
# Node ID 8aa1605e58f187b42c13715e527aa9c6247541a8
# Parent  3d006afee054a8a573b2dc134d6fa0bf3baae892
Fixed: rounding methods NaN aware in Formatter

diff -r 3d006afee054 -r 8aa1605e58f1 artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Thu Aug 02 16:08:51 2018 +0200
@@ -58,11 +58,12 @@
     }
 
     public static final double round(double x, double precision) {
+        // REMARK/FIXME: Gives 0 for NaN - is this intended?
         return Math.round(x * precision)/precision;
     }
 
     public static final double round(double x) {
-        return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION;
+        return round(x, DEFAULT_STEP_PRECISION);
     }
 
     /**
diff -r 3d006afee054 -r 8aa1605e58f1 artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Thu Aug 02 16:08:51 2018 +0200
@@ -386,6 +386,8 @@
     }
 
     public static double roundFlowDepth(final double value) {
+        if (Double.isNaN(value))
+            return Double.NaN;
         return Math.round(value * FLOWDEPTH_ROUND_MULT) / FLOWDEPTH_ROUND_MULT;
     }
 
@@ -394,6 +396,8 @@
     }
 
     public static double roundW(final double value) {
+        if (Double.isNaN(value))
+            return Double.NaN;
         return Math.round(value * W_ROUND_MULT) / W_ROUND_MULT;
     }
 


More information about the Dive4Elements-commits mailing list