From 185ee37ac547e3826a74afbef1d9f00077aaf405 Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Mon, 8 Aug 2022 00:38:29 +0200 Subject: [PATCH] [bugfix] Fix comparison of NaN values for xs:float and xs:double --- .../src/main/java/org/exist/xquery/value/DoubleValue.java | 6 +++++- .../src/main/java/org/exist/xquery/value/FloatValue.java | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java b/exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java index d97d4033b79..1bc2c21ece9 100644 --- a/exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java +++ b/exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java @@ -151,7 +151,11 @@ public boolean isPositive() { @Override protected @Nullable IntSupplier createComparisonWith(final NumericValue other) { final IntSupplier comparison; - if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) { + if (isNaN()) { + comparison = () -> Constants.INFERIOR; + } else if (other.isNaN()) { + comparison = () -> Constants.SUPERIOR; + } else if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) { comparison = () -> Constants.EQUAL; } else if (other instanceof IntegerValue) { comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue)other).value)); diff --git a/exist-core/src/main/java/org/exist/xquery/value/FloatValue.java b/exist-core/src/main/java/org/exist/xquery/value/FloatValue.java index 597f429c6c2..1d4b7847c2c 100644 --- a/exist-core/src/main/java/org/exist/xquery/value/FloatValue.java +++ b/exist-core/src/main/java/org/exist/xquery/value/FloatValue.java @@ -150,8 +150,11 @@ public boolean isPositive() { @Override protected @Nullable IntSupplier createComparisonWith(final NumericValue other) { final IntSupplier comparison; - - if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) { + if (isNaN()) { + comparison = () -> Constants.INFERIOR; + } else if (other.isNaN()) { + comparison = () -> Constants.SUPERIOR; + } else if (isInfinite() && other.isInfinite() && isPositive() == other.isPositive()) { comparison = () -> Constants.EQUAL; } else if (other instanceof IntegerValue) { comparison = () -> BigDecimal.valueOf(value).compareTo(new BigDecimal(((IntegerValue)other).value));