Skip to content

Fix OverflowError in number functions for large integers (#419) - #519

Closed
brubasree007 wants to merge 1 commit into
python-humanize:mainfrom
brubasree007:fix-number-overflow-large-integers
Closed

brubasree007 wants to merge 1 commit into
python-humanize:mainfrom
brubasree007:fix-number-overflow-large-integers

Conversation

@brubasree007

@brubasree007 brubasree007 commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #419

Changes proposed in this pull request:

  • In ordinal, intword, apnumber, and fractional: parse integer values first via int(value) and catch OverflowError alongside (TypeError, ValueError), preventing redundant float conversions on discrete integer values.
  • In intcomma: ensure integer strings without decimals are parsed as integers before attempting float fallback, avoiding +Inf saturation for large integer strings.
  • In scientific: format numbers exceeding standard float bounds using decimal.Decimal into superscript notation without overflow.
  • In clamp and metric: short-circuit non-finite checks with if not isinstance(value, int) and not math.isfinite(value):.
  • In intword: wrap division in OverflowError handling using Decimal for extreme scales beyond powers.
  • Added test_number_functions_large_integers in tests/test_number.py testing 10**400 across all affected functions (all 733 tests pass).

@hugovk

hugovk commented Nov 16, 2026

Copy link
Copy Markdown
Member

See all the other duplicates linked to #419.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several number functions raise OverflowError on integers larger than a float

2 participants