Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 5151:240ff7aeb6de
DoubleUtil: Use tolerance when comparing doubles in explode(). Fixes flys/issue1132.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 01 Mar 2013 10:04:57 +0100 |
parents | 345f3bba6f15 |
children |
comparison
equal
deleted
inserted
replaced
5150:345f3bba6f15 | 5151:240ff7aeb6de |
---|---|
13 { | 13 { |
14 /** Private logger. */ | 14 /** Private logger. */ |
15 private static Logger log = Logger.getLogger(DoubleUtil.class); | 15 private static Logger log = Logger.getLogger(DoubleUtil.class); |
16 | 16 |
17 public static final double DEFAULT_STEP_PRECISION = 1e6; | 17 public static final double DEFAULT_STEP_PRECISION = 1e6; |
18 | |
19 /** EPSILON for comparison of double precision values. */ | |
20 public static final double EPSILON = 1e-4; | |
18 | 21 |
19 private DoubleUtil() { | 22 private DoubleUtil() { |
20 } | 23 } |
21 | 24 |
22 public static final double [] explode(double from, double to, double step) { | 25 public static final double [] explode(double from, double to, double step) { |
58 } | 61 } |
59 | 62 |
60 double max = Math.max(from, to); | 63 double max = Math.max(from, to); |
61 | 64 |
62 for (int idx = 0; idx < num; idx++) { | 65 for (int idx = 0; idx < num; idx++) { |
63 if (lower > max) { | 66 if (lower - max > EPSILON) { |
64 return Arrays.copyOfRange(values, 0, idx); | 67 return Arrays.copyOfRange(values, 0, idx); |
65 } | 68 } |
66 | 69 |
67 values[idx] = round(lower, precision); | 70 values[idx] = round(lower, precision); |
68 lower += step; | 71 lower += step; |