Repository navigation
Conversation
There was a problem hiding this comment.
The integer overflow case is fixed, but the same finite value passed through the accepted string input still renders as infinity: scientific(10**400) → 1.00 x 10⁴⁰⁰, while scientific("1" + "0" * 400) → +Inf. I reproduced both at this head. float(huge_integer_string) returns infinity rather than raising OverflowError, so the Decimal fallback is skipped for that form. Consider an integer-string regression and detecting that finite form before the float conversion. I ran these checks on Python 3.12 with English locale hooks; no full package test run.
float() turns a numeric string that is too large into infinity and one that is too small into zero, so scientific() rendered '1' followed by 400 zeros as +Inf and '1e-400' as 0. Format such strings with Decimal.
|
Thanks, fixed in 40a2faf: numeric strings beyond float range (both too large and too small, e.g. |
Fixes #
Changes proposed in this pull request:
scientificfalls back toDecimalformatting whenfloat()overflows, so an integer larger than the float range no longer raisesOverflowErrorDecimalis only used on the overflow path10**400, its negative, a precision argument and precision0, plus0to pin the unchanged pathSame family as #420:
scientificconverts withfloat()first, which raisesOverflowErrorfor an integer beyond the float range and is not covered by theexcept (ValueError, TypeError)clause.After this change it returns
'1.00 x 10⁴⁰⁰'.Decimalis not used for all integers becauseformat(Decimal(0), ".2e")gives0.00e+2, which would breakscientific(0).