Respect rounding mode when quantizing sub-ULP values - #152
Open
chiliec wants to merge 1 commit into
Open
Conversation
Quantize truncated any value with fewer digits than the target exponent straight to zero, ignoring the context's Rounding mode. RoundCeiling of a positive sub-ULP value (e.g. 0.002 to exponent -1) returned 0.0 instead of 0.1, and RoundFloor of a negative one lost the rounding entirely. Round the discarded coefficient through the configured Rounder instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #140
What
Context.Quantizeignored the rounding mode when the input had fewer significant digits than the target exponent (i.e. its magnitude was smaller than one unit in the last place). It truncated straight to zero regardless of the configuredRounder:RoundCeiling(1.002, -1)already returned1.1; only the sub-ULP case was wrong.Fix
In the
p < 0branch ofquantize, run the discarded coefficient through the context'sRounding.ShouldAddOne(the same mechanism the normal rounding path uses) instead of unconditionally zeroing it.Tests
Added
TestQuantizeRoundingcovering the reported case plus every rounding mode (ceiling/floor/up/down/half-up/half-even, positive and negative). Verified genuine RED→GREEN:Full suite (including the GDA conformance tests) is green:
Happy to adjust.