@@ -201,6 +201,30 @@ Query termsQuery(String field, List<Object> values) {
201201 return HalfFloatPoint .newSetQuery (field , v );
202202 }
203203
204+ private float nextDown (float f ) {
205+ // HalfFloatPoint.nextDown considers that -0 is the same as +0
206+ // while point ranges are consistent with Float.compare, so
207+ // they consider that -0 < +0, so we explicitly make sure
208+ // that nextDown(+0) returns -0
209+ if (Float .floatToIntBits (f ) == Float .floatToIntBits (0f )) {
210+ return -0f ;
211+ } else {
212+ return HalfFloatPoint .nextDown (f );
213+ }
214+ }
215+
216+ private float nextUp (float f ) {
217+ // HalfFloatPoint.nextUp considers that -0 is the same as +0
218+ // while point ranges are consistent with Float.compare, so
219+ // they consider that -0 < +0, so we explicitly make sure
220+ // that nextUp(-0) returns +0
221+ if (Float .floatToIntBits (f ) == Float .floatToIntBits (-0f )) {
222+ return +0f ;
223+ } else {
224+ return HalfFloatPoint .nextUp (f );
225+ }
226+ }
227+
204228 @ Override
205229 Query rangeQuery (String field , Object lowerTerm , Object upperTerm ,
206230 boolean includeLower , boolean includeUpper ) {
@@ -209,16 +233,16 @@ Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
209233 if (lowerTerm != null ) {
210234 l = parse (lowerTerm );
211235 if (includeLower ) {
212- l = Math . nextDown (l );
236+ l = nextDown (l );
213237 }
214238 l = HalfFloatPoint .nextUp (l );
215239 }
216240 if (upperTerm != null ) {
217241 u = parse (upperTerm );
218242 if (includeUpper ) {
219- u = Math . nextUp (u );
243+ u = nextUp (u );
220244 }
221- u = HalfFloatPoint . nextDown (u );
245+ u = nextDown (u );
222246 }
223247 return HalfFloatPoint .newRangeQuery (field , l , u );
224248 }
@@ -291,6 +315,30 @@ Query termsQuery(String field, List<Object> values) {
291315 return FloatPoint .newSetQuery (field , v );
292316 }
293317
318+ private float nextDown (float f ) {
319+ // Math.nextDown considers that -0 is the same as +0
320+ // while point ranges are consistent with Float.compare, so
321+ // they consider that -0 < +0, so we explicitly make sure
322+ // that nextDown(+0) returns -0
323+ if (Float .floatToIntBits (f ) == Float .floatToIntBits (0f )) {
324+ return -0f ;
325+ } else {
326+ return Math .nextDown (f );
327+ }
328+ }
329+
330+ private float nextUp (float f ) {
331+ // Math.nextUp considers that -0 is the same as +0
332+ // while point ranges are consistent with Float.compare, so
333+ // they consider that -0 < +0, so we explicitly make sure
334+ // that nextUp(-0) returns +0
335+ if (Float .floatToIntBits (f ) == Float .floatToIntBits (-0f )) {
336+ return +0f ;
337+ } else {
338+ return Math .nextUp (f );
339+ }
340+ }
341+
294342 @ Override
295343 Query rangeQuery (String field , Object lowerTerm , Object upperTerm ,
296344 boolean includeLower , boolean includeUpper ) {
@@ -299,13 +347,13 @@ Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
299347 if (lowerTerm != null ) {
300348 l = parse (lowerTerm );
301349 if (includeLower == false ) {
302- l = Math . nextUp (l );
350+ l = nextUp (l );
303351 }
304352 }
305353 if (upperTerm != null ) {
306354 u = parse (upperTerm );
307355 if (includeUpper == false ) {
308- u = Math . nextDown (u );
356+ u = nextDown (u );
309357 }
310358 }
311359 return FloatPoint .newRangeQuery (field , l , u );
@@ -379,6 +427,30 @@ Query termsQuery(String field, List<Object> values) {
379427 return DoublePoint .newSetQuery (field , v );
380428 }
381429
430+ private double nextDown (double d ) {
431+ // Math.nextDown considers that -0 is the same as +0
432+ // while point ranges are consistent with Double.compare, so
433+ // they consider that -0 < +0, so we explicitly make sure
434+ // that nextDown(+0) returns -0
435+ if (Double .doubleToLongBits (d ) == Double .doubleToLongBits (0d )) {
436+ return -0d ;
437+ } else {
438+ return Math .nextDown (d );
439+ }
440+ }
441+
442+ private double nextUp (double d ) {
443+ // Math.nextUp considers that -0 is the same as +0
444+ // while point ranges are consistent with Double.compare, so
445+ // they consider that -0 < +0, so we explicitly make sure
446+ // that nextUp(-0) returns +0
447+ if (Double .doubleToLongBits (d ) == Double .doubleToLongBits (-0d )) {
448+ return +0d ;
449+ } else {
450+ return Math .nextUp (d );
451+ }
452+ }
453+
382454 @ Override
383455 Query rangeQuery (String field , Object lowerTerm , Object upperTerm ,
384456 boolean includeLower , boolean includeUpper ) {
@@ -387,13 +459,13 @@ Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
387459 if (lowerTerm != null ) {
388460 l = parse (lowerTerm );
389461 if (includeLower == false ) {
390- l = Math . nextUp (l );
462+ l = nextUp (l );
391463 }
392464 }
393465 if (upperTerm != null ) {
394466 u = parse (upperTerm );
395467 if (includeUpper == false ) {
396- u = Math . nextDown (u );
468+ u = nextDown (u );
397469 }
398470 }
399471 return DoublePoint .newRangeQuery (field , l , u );
0 commit comments