Skip to content

Commit 6f263a0

Browse files
committed
[bugfix] Fix comparison of NaN values for xs:float and xs:double
1 parent 3b3c68a commit 6f263a0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ public boolean isPositive() {
147147
@Override
148148
protected @Nullable IntSupplier createComparisonWith(final NumericValue other) {
149149
final IntSupplier comparison;
150-
if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
150+
if (isNaN()) {
151+
comparison = () -> Constants.INFERIOR;
152+
} else if (other.isNaN()) {
153+
comparison = () -> Constants.SUPERIOR;
154+
} else if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
151155
comparison = () -> Constants.EQUAL;
152156
} else if (other instanceof IntegerValue) {
153157
comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue) other).value));

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,11 @@ public boolean isPositive() {
150150
@Override
151151
protected @Nullable IntSupplier createComparisonWith(final NumericValue other) {
152152
final IntSupplier comparison;
153-
154-
if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
153+
if (isNaN()) {
154+
comparison = () -> Constants.INFERIOR;
155+
} else if (other.isNaN()) {
156+
comparison = () -> Constants.SUPERIOR;
157+
} else if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) {
155158
comparison = () -> Constants.EQUAL;
156159
} else if (other instanceof IntegerValue) {
157160
comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue)other).value));

0 commit comments

Comments
 (0)