Skip to content

Fix float/double facet checks to use native comparison instead of compareTo#1664

Open
gdesrosiers1805 wants to merge 1 commit intoapache:mainfrom
gdesrosiers1805:bugfix/daffodil-3072
Open

Fix float/double facet checks to use native comparison instead of compareTo#1664
gdesrosiers1805 wants to merge 1 commit intoapache:mainfrom
gdesrosiers1805:bugfix/daffodil-3072

Conversation

@gdesrosiers1805
Copy link
Copy Markdown

@gdesrosiers1805 gdesrosiers1805 commented May 4, 2026

Float|Double.compareTo define a total order where NaN > all values and
-0.0 < +0.0, which violates XSD semantics. XSD requires NaN to be
incomparable (failing all facets) and -0.0 to equal +0.0.

- Replace f.compareTo()/d.compareTo() with native f >= and
  d >= (and corresponding >, <=, <) so that minInclusive,
  maxInclusive, minExclusive, and maxExclusive correctly handle NaN,
  +/-INF, and -0.0 for xs:float and xs:double types.
- Add unit tests to Facets.tdml covering all four facets for xs:float
  and xs:double, exercising IEEE 754 special values: NaN, +INF, -INF,
  and -0.0.

DAFFODIL-3072

Copy link
Copy Markdown
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes to the code, would prefer to see TDML tests instead of the custom tests.

Copy link
Copy Markdown
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes to the code, would prefer to see TDML tests instead of the custom tests.

@gdesrosiers1805 gdesrosiers1805 force-pushed the bugfix/daffodil-3072 branch from 3d21fc4 to eaf3845 Compare May 5, 2026 19:20
Copy link
Copy Markdown
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 with fix to not ignore unexpected validation errors

…pareTo

Float|Double.compareTo define a total order where NaN > all values and
-0.0 < +0.0, which violates XSD semantics. XSD requires NaN to be
incomparable (failing all facets) and -0.0 to equal +0.0.

- Replace f.compareTo()/d.compareTo() with native f >= and
  d >= (and corresponding >, <=, <) so that minInclusive,
  maxInclusive, minExclusive, and maxExclusive correctly handle NaN,
  +/-INF, and -0.0 for xs:float and xs:double types.
- Add unit tests to Facets.tdml covering all four facets for xs:float
  and xs:double, exercising IEEE 754 special values: NaN, +INF, -INF,
  and -0.0.

DAFFODIL-3072
@gdesrosiers1805 gdesrosiers1805 force-pushed the bugfix/daffodil-3072 branch from eaf3845 to 5a3ed14 Compare May 7, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants