public class DoubleComparator extends NumberComparator {
public DoubleComparator() {
}
public DoubleComparator(final byte[] value) {
super(value);
}
@Override
public int compareTo(byte[] value, int offset, int length) {
double d1 = Bytes.toDouble(super.value);
double d2 = Bytes.toDouble(value, offset);
if (d1 < d2)
return -1; // Neither val is NaN, thisVal is smaller
if (d1 > d2)
return 1; // Neither val is NaN, thisVal is larger
long thisBits = Double.doubleToLongBits(d1);
long anotherBits = Double.doubleToLongBits(d2);
return (thisBits == anotherBits ? 0 : // Values are equal
(thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
1));
}