Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

866 Introduce and exploit new numeric-compare() function #881

Merged
merged 2 commits into from
Dec 19, 2023

Conversation

michaelhkay
Copy link
Contributor

Fix #866

The proposal introduces a new fn:numeric-compare function that differs from lt/eq primarily in that decimals are compared retaining their full precision, rather than converting them to doubles which may lose precision. This makes the comparison fully transitive which makes it safe to use in all sorting algorithms.

The new comparison semantics are exploited in max(), min(), and sort(), and indirectly in highest() and lowest(); they are also referenced for comparing numeric values in XSLT xsl:sort (and therefore indirectly in xsl:merge) and in XQuery order by.

An effect of the change is that max() and min() applied to a sequence of integers now return an integer, not a double.

Copy link
Contributor

@ChristianGruen ChristianGruen left a comment

Choose a reason for hiding this comment

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

See #866 (comment) for the idea to extend fn:compare and drop fn:atomic-equal (and fn:numeric-compare).

If we add fn:numeric-compare, we should probably move it from “4.3 Comparison operators on numeric values” to “4.4 Functions on numeric values”.

If we generalize fn:compare, it needs to be moved from “5.3 Comparison of strings” to possibly “14.2 Comparison functions” (which includes fn:atomic-equal).

@ndw
Copy link
Contributor

ndw commented Dec 12, 2023

The CG agreed to accept this PR at meeting 058

@ChristianGruen
Copy link
Contributor

@michaelhkay The only edit I would propose before merging the PR is to move fn:numeric-compare from “4.3 Comparison operators on numeric values” to “4.4 Functions on numeric values” (unless we make it private).

@ndw ndw added the Blocked PR is blocked (has merge conflicts, doesn't format, etc.) label Dec 12, 2023
@ChristianGruen ChristianGruen added the Tests Needed Tests need to be written or merged label Dec 16, 2023
@ChristianGruen
Copy link
Contributor

ChristianGruen commented Dec 16, 2023

In addition, as @Arithmeticus indicated, we’ll need to define how -0e0 and 0e0 are compared.

My first guess would be that -0e0 should be defined to be smaller than 0e0. (I shouldn’t judge without diving into the details)

@michaelhkay
Copy link
Contributor Author

I have updated the PR:

  • to remove conflicts
  • to move the new function to section 4.4 as requested
  • to state that positive and negative zero are equal

@ChristianGruen ChristianGruen added Propose Merge without Discussion Change is editorial or minor and removed Blocked PR is blocked (has merge conflicts, doesn't format, etc.) labels Dec 18, 2023
@ndw
Copy link
Contributor

ndw commented Dec 19, 2023

The CG agreed to merge this PR without discussion at meeting 59.

@ndw ndw merged commit 0bf8239 into qt4cg:master Dec 19, 2023
2 checks passed
@ChristianGruen ChristianGruen removed the Propose Merge without Discussion Change is editorial or minor label Jan 2, 2024
@michaelhkay michaelhkay added Overtaken PR was accepted but has no effect on current spec and removed Tests Needed Tests need to be written or merged labels Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Overtaken PR was accepted but has no effect on current spec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fn:sort, and XSLT and XQuery sorting, should use transitive comparisons
3 participants