Repository navigation
Round away from zero in ROUND_UP for values far below the rounding position - #560
Open
Shaisolaris wants to merge 1 commit into
Open
Shaisolaris wants to merge 1 commit into
Shaisolaris wants to merge 1 commit into
Conversation
…sition
VpMidRound zeroed the value whenever the rounding position was left of
the first digit word, except for ROUND_CEILING and ROUND_FLOOR. ROUND_UP
also rounds any nonzero remainder away from zero, so it gave 0 instead of
the next unit, e.g. BigDecimal("1e-10").round(0, :up) returned 0 while
BigDecimal("1e-7").round(0, :up) returned 1.
This branch has not been deployed
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.
round(n, :up)returns zero for a nonzero value that lies more than one internal digit word (9 decimal digits) below the rounding position:VpMidRoundtruncates everything when the rounding position is left of the first word, but keeps going forROUND_CEILINGandROUND_FLOORso they can round to the next unit.ROUND_UPneeds the same treatment, since any nonzero remainder rounds away from zero. The change adds it to that check; the existing path (exptoadd) then produces the right result.Testing:
test_round_up_value_far_below_rounding_positionfails before the change and passes after.test/bigdecimalpass with the change (270 tests, 0 failures, 13 omissions) on Ruby 3.3.8, Linux x86_64.test_sigand JRuby were not run.round(n, mode)against exactRationalrounding for all seven modes (60,000 cases, exponents -60..40, n -45..45) found 4,800:upmismatches before and none after.