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

Standard library function round() does not round half numbers up. #698

Open
stxue1 opened this issue Jul 2, 2024 · 0 comments
Open

Standard library function round() does not round half numbers up. #698

stxue1 opened this issue Jul 2, 2024 · 0 comments
Labels
interop Bears on spec compatibility

Comments

@stxue1
Copy link

stxue1 commented Jul 2, 2024

Half numbers in miniwdl are rounded down instead of rounding up, which differs with the spec:
https://github.com/openwdl/wdl/blob/9c0b9cf4586508a9e6260cc5c5e562e21f625aac/SPEC.md?plain=1#L6279

Rounds a floating point number to the nearest integer based on standard rounding rules ("round half up").

The spec also has an example of this behavior (though the example json output is supposed to be [true, true] instead of true.
https://github.com/openwdl/wdl/blob/9c0b9cf4586508a9e6260cc5c5e562e21f625aac/SPEC.md?plain=1#L6289-L6306

With the WDL workflow below:

version 1.1

workflow test_round {
  input {
    Int i1 = 2
  }

  Float f1 = i1 + 0.50
  Float f2 = i1 + 0.51
  
  output {
    Int round_f1 = round(f1)
    Int round_f2 = round(f2)
  }
}

The output is:

{
  "dir": "/home/heaucques/Documents/wdl-conformance-tests/20240701_180506_test_round",
  "outputs": {
    "test_round.round_f1": 2,
    "test_round.round_f2": 3
  }
}

Even though both integer outputs should be 3.

This may be due to how the round function is implemented.

static([Type.Float()], Type.Int(), "round")(lambda v: Value.Int(round(v.value)))

It looks like the standard library function depends on python's round function, and python rounds half numbers towards the "even" choice.
https://docs.python.org/3/library/functions.html#round

Python 3.12.4 (main, Jun  8 2024, 18:29:57) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> round(0.5)
0
@mlin mlin added the interop Bears on spec compatibility label Jul 3, 2024
@github-project-automation github-project-automation bot moved this to Backlog in miniwdl Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Bears on spec compatibility
Projects
Status: Backlog
Development

No branches or pull requests

2 participants