changeset 9367:8aa1605e58f1

Fixed: rounding methods NaN aware in Formatter
author mschaefer
date Thu, 02 Aug 2018 16:08:51 +0200
parents 3d006afee054
children 6f7e92c16050
files artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
diffstat 2 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }
 
     /**
--- 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;
     }
 

http://dive4elements.wald.intevation.org