| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
intword() detected the post-rounding carry into the next magnitude with 'rounded_value * power == powers[ordinal + 1]'. Above ~10**22 that product is evaluated in floating point and no longer equals the exact next power, so the carry was skipped and the value was rendered against the lower magnitude: intword(10**24 - 1) returned '1000.0 sextillion' instead of '1.0 septillion' (same for 10**27, 10**30, 10**33). Compare rounded_value against the exact integer ratio powers[ordinal+1] // power instead, keeping the comparison in exact integer/short-float terms. This mirrors the recently fixed carry handling in metric() (python-humanize#328) and naturalsize() (python-humanize#329).
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #346 +/- ##
=======================================
Coverage 99.56% 99.56%
=======================================
Files 12 12
Lines 913 925 +12
=======================================
+ Hits 909 921 +12
Misses 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Problem
intword() decides whether rounding pushed a value up into the next magnitude
with:
For values above ~10**22, rounded_value * power is evaluated in floating
point and no longer equals the exact powers[ordinal + 1], so the carry is
skipped and the number is rendered against the lower magnitude:
The same happens at 10**30 and 10**33.
Fix
Compare rounded_value against the exact integer ratio
powers[ordinal + 1] // power, keeping the check in exact integer terms rather
than relying on a large float product. This mirrors the recently fixed carry
handling in metric() (#328) and naturalsize() (#329).
Tests
test_intword_rounding_rollover asserts the correct roll-over across every
affected magnitude (10**24/27/30/33 - 1), plus a couple of just-below cases
that must not roll over, guarding both directions.
pytest → 716 passed. ruff check / ruff format --check clean.