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

op:numeric-mod returns incorrect remainders #305

Closed
aj-stein-nist opened this issue Feb 6, 2024 · 1 comment · Fixed by #306
Closed

op:numeric-mod returns incorrect remainders #305

aj-stein-nist opened this issue Feb 6, 2024 · 1 comment · Fixed by #306
Assignees
Labels
bug Something isn't working java Pull requests that update Java code
Milestone

Comments

@aj-stein-nist
Copy link
Collaborator

aj-stein-nist commented Feb 6, 2024

Describe the bug

While testing example Metaschema modules for usnistgov/metaschema#530, I was unable to correctly use mod to compute the remainder of integer division between two numeric values. Debugging indicates there is an issue with the implementation of op:numeric-mod (aliased to mod like in XPath 3.0, this holds for Metapath), potentially in the context that handles decimal precision (review the straightforward implementation code for the function, it is unclear how else there can be a bug, but further investigation needed).

Who is the bug affecting?

Developers of Metaschema modules or Metaschema-enabled tools who need functioning numeric operations (including mod) for advanced constraint usage.

What is affected by this bug?

Any field or flag element in core Metaschema syntax where a module developer can use mod to constrain model requirements (currently, that is most impactful for @target and @test on relevant constraint types).

When does this occur?

Consistently.

How do we replicate the issue?

{What are the steps to reproduce the behavior?

  1. Run the following tests.
  2. Review unexpected errors because the tool's code is performing normal integer division, not modulo division.

Expected behavior (i.e. solution)

Modulo division would successfully divide [the official examples test vectors for Metapath matching the op:mod-numeric examples inputs and function outputs.

Other Comments

N/A

@aj-stein-nist aj-stein-nist added bug Something isn't working java Pull requests that update Java code labels Feb 6, 2024
@aj-stein-nist aj-stein-nist changed the title op:numeric-mod returns incorrect remainders for integer op:numeric-mod returns incorrect remainders Feb 6, 2024
@aj-stein-nist
Copy link
Collaborator Author

Paired with @david-waltermire and it turns out it is mapping the mod expression to the correct function from the core parser handler driven by the ANTLR grammar (in BuildCSTVisitor). I will update the issue with the broken tests to explain the bug and then make it a fix branch once I am done with the small, tactical PR. 😄

@aj-stein-nist aj-stein-nist self-assigned this Feb 6, 2024
aj-stein-nist added a commit to aj-stein-nist/metaschema-java that referenced this issue Feb 6, 2024
aj-stein-nist added a commit to aj-stein-nist/metaschema-java that referenced this issue Feb 6, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 6, 2024
* Add broken tests for #305 bug report

* Modulo invoke mod-numeric not idiv for #305.
@david-waltermire david-waltermire added this to the v1.0.0-M2 milestone Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working java Pull requests that update Java code
Projects
None yet
2 participants