From 7ea6cd688886b74d534c865727635681e4ba6034 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 19 Apr 2013 21:19:07 +0200 Subject: [PATCH] use Double/Float.compare for stable and correct float sort order --- .../fieldcomparator/DoubleValuesComparatorBase.java | 8 +------- .../fielddata/fieldcomparator/FloatValuesComparator.java | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorBase.java b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorBase.java index bcaa047cfa3..4af80a427ec 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorBase.java +++ b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorBase.java @@ -62,13 +62,7 @@ abstract class DoubleValuesComparatorBase extends NumberCompar } static final int compare(double left, double right) { - if (left > right) { - return 1; - } else if (left < right) { - return -1; - } else { - return 0; - } + return Double.compare(left, right); } static final class MultiValueWrapper extends DoubleValues.Filtered { diff --git a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparator.java b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparator.java index 960c60b0ca7..0a41d9b3f16 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparator.java +++ b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/FloatValuesComparator.java @@ -39,13 +39,7 @@ public final class FloatValuesComparator extends DoubleValuesComparatorBase v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } + return Float.compare(v1, v2); } @Override