Fix fractional(0) returning "0/1" instead of "0" - #351
Open
Sreekant13 wants to merge 1 commit into
Open
Conversation
fractional() gated the whole-number return on `whole_number` being truthy, so 0 (where whole_number == 0) fell through to the fraction branch and rendered as "0/1". Since `numerator == 0 and denominator == 1` already uniquely identifies a whole number (including 0), drop the redundant `whole_number and`. Now fractional(0) returns "0". Added regression test cases.
Author
|
Hi @hugovk, gentle nudge on this small fix whenever you have time. Thanks for maintaining humanize. |
Author
|
Flagging an overlap, since I only noticed it now: @semx opened #354 a few days after this one, and it covers the same Their fix folds any whole-valued fractional part into the integer part, which handles both cases in one place, so it is the more complete change of the two. I am happy to close this in favour of #354 if that is the direction you prefer, or to add their case here if you would rather keep this one. Whichever is less work for you. |
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.
fractional(0)returns"0/1"instead of"0", even though every other whole number renders bare:The whole-number return branch was gated on
whole_numberbeing truthy, so0(wherewhole_number == 0) skipped it and fell through to the fraction branch, producing"0/1". Sincenumerator == 0 and denominator == 1already uniquely identifies a whole number (including0), thewhole_number andcheck is both redundant and wrong for0. Removing it makesfractional(0)return"0", consistent withfractional(3),fractional(2.0), etc.Fixes # (no linked issue - small self-contained bug fix)
Changes proposed in this pull request:
whole_number andguard infractional()so0is treated as a whole number and returns"0"(previously"0/1").(0, "0")and(0.0, "0")totest_fractional.