use Double/Float.compare for stable and correct float sort order

This commit is contained in:
Simon Willnauer 2013-04-19 21:19:07 +02:00
parent 1483a3a0e5
commit 7ea6cd6888
2 changed files with 2 additions and 14 deletions

View File

@ -62,13 +62,7 @@ abstract class DoubleValuesComparatorBase<T extends Number> 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 {

View File

@ -39,13 +39,7 @@ public final class FloatValuesComparator extends DoubleValuesComparatorBase<Floa
public int compare(int slot1, int slot2) {
final float v1 = values[slot1];
final float v2 = values[slot2];
if (v1 > v2) {
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
return Float.compare(v1, v2);
}
@Override