Skip to content

Commit 3b3c68a

Browse files
committed
[bugfix] Fix comparison of INF and -INF values for xs:float and xs:double
1 parent 8689280 commit 3b3c68a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,21 @@ public boolean isPositive() {
146146

147147
@Override
148148
protected @Nullable IntSupplier createComparisonWith(final NumericValue other) {
149-
if (other instanceof IntegerValue) {
150-
return () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue) other).value));
151-
}
152-
if (other instanceof DecimalValue) {
153-
return () -> BigDecimal.valueOf(value).compareTo(((DecimalValue) other).value);
154-
}
155-
if (other instanceof DoubleValue) {
156-
return () -> Double.compare(value, ((DoubleValue) other).value);
157-
}
158-
if (other instanceof FloatValue) {
159-
return () -> Double.compare(value, ((FloatValue) other).value);
160-
}
161-
return null;
149+
final IntSupplier comparison;
150+
if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
151+
comparison = () -> Constants.EQUAL;
152+
} else if (other instanceof IntegerValue) {
153+
comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue) other).value));
154+
} else if (other instanceof DecimalValue) {
155+
comparison = () -> BigDecimal.valueOf(value).compareTo(((DecimalValue) other).value);
156+
} else if (other instanceof DoubleValue) {
157+
comparison = () -> Double.compare(value, ((DoubleValue) other).value);
158+
} else if (other instanceof FloatValue) {
159+
comparison = () -> Double.compare(value, ((FloatValue) other).value);
160+
} else {
161+
comparison = null;
162+
}
163+
return comparison;
162164
}
163165

164166
@Override

exist-core/src/main/java/org/exist/xquery/value/FloatValue.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ public boolean isPositive() {
150150
@Override
151151
protected @Nullable IntSupplier createComparisonWith(final NumericValue other) {
152152
final IntSupplier comparison;
153-
if (other instanceof IntegerValue) {
153+
154+
if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
155+
comparison = () -> Constants.EQUAL;
156+
} else if (other instanceof IntegerValue) {
154157
comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue)other).value));
155158
} else if (other instanceof DecimalValue) {
156159
final BigDecimal promoted = new BigDecimal(Float.toString(value));

0 commit comments

Comments
 (0)