Make the rounding rule match the baseline #746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In PR #392 a rule was added that rounding must be done by the IEEE 754 rule "towards positive infinity". This rule is also known as rounding up, or ceiling (it rounds 1.1 to 2).
However, the baseline implementation does not do this - instead, it rounds to nearest, with ties towards positive infinity.
The same PR adds an extra rounding step that I think improves the resilience against accumulated floating-point errors (by using knowledge about the input values), but does not actually change its rounding behavior otherwise.
I'm assuming that the current baseline behavior is intended, making the error be in the rule text (probably based on a simple misunderstanding of the standard). Therefore I propose a rule change to make the rules match the baseline implementation.
Since the other implementations are verified against the baseline output rather than directly against the rules, this avoids any need for code changes.
This PR also adds a few test cases to the rounding test, that I used to verify the expected rounding rules for both positive and negative numbers, without it being obscured by the floating-point inaccuracy. (Both the baseline and baseline_original_rounding implementations pass these tests, but code that uses any of the IEEE 754 rounding rules won't.)