Skip to content

Commit 58170f0

Browse files
authored
Merge pull request #127 from tynanford/range_infinity
Address issue #56 - permit half-ranges
2 parents 8369d48 + 7186073 commit 58170f0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

epics-util/src/main/java/org/epics/util/stats/Range.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,16 @@ public int hashCode() {
213213
* @return the range
214214
*/
215215
public static Range of(final double minValue, final double maxValue) {
216-
if (Double.isNaN(minValue) || Double.isNaN(maxValue)) {
216+
if (Double.isNaN(minValue) && Double.isNaN(maxValue)) {
217217
return Range.UNDEFINED;
218218
}
219-
219+
else if (Double.isNaN(minValue)) {
220+
return new Range(Double.NEGATIVE_INFINITY, maxValue, false);
221+
}
222+
else if (Double.isNaN(maxValue)) {
223+
return new Range(minValue, Double.POSITIVE_INFINITY, false);
224+
}
225+
220226
if (minValue > maxValue) {
221227
return new Range(maxValue, minValue, true);
222228
}

epics-util/src/test/java/org/epics/util/stats/RangeTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public void range3() throws Exception {
4444
@Test
4545
public void range4() throws Exception {
4646
Range range = Range.of(0.0, Double.NaN);
47-
assertThat(range, sameInstance(Range.undefined()));
47+
assertThat(range.getMinimum(), equalTo(0.0));
48+
assertThat(range.getMaximum(), equalTo(Double.POSITIVE_INFINITY));
49+
assertThat(range.isReversed(), equalTo(false));
50+
assertThat(range.toString(), equalTo("[0.0 - Infinity]"));
4851
}
4952

5053
@Test

0 commit comments

Comments
 (0)