Title: Decimal to int conversion with engineering notation costly despite failing · Issue #139957 · python/cpython · GitHub
Open Graph Title: Decimal to int conversion with engineering notation costly despite failing · Issue #139957 · python/cpython
X Title: Decimal to int conversion with engineering notation costly despite failing · Issue #139957 · python/cpython
Description: Bug report Bug description: Adding many digits to engineering notation causes cpython to work very hard trying to do the conversion, only for it to fail anyway. >>> x = decimal.Decimal('1.0E+10000') >>> int(x) Traceback (most recent call...
Open Graph Description: Bug report Bug description: Adding many digits to engineering notation causes cpython to work very hard trying to do the conversion, only for it to fail anyway. >>> x = decimal.Decimal('1.0E+10000'...
X Description: Bug report Bug description: Adding many digits to engineering notation causes cpython to work very hard trying to do the conversion, only for it to fail anyway. >>> x = decimal.Decimal(...
Opengraph URL: https://github.com/python/cpython/issues/139957
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Decimal to int conversion with engineering notation costly despite failing","articleBody":"# Bug report\n\n### Bug description:\n\nAdding many digits to engineering notation causes cpython to work very hard trying to do the conversion, only for it to fail anyway.\n\n```python\n>>> x = decimal.Decimal('1.0E+10000')\n>>> int(x)\nTraceback (most recent call last):\n File \"\u003cstdin>\", line 1, in \u003cmodule>\nValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit\n```\n\nBut the time it takes goes up when you add extra digits. It appears to be unbounded.\n```python\n>>> timeit.timeit(setup=\"import decimal\", stmt=\"x = decimal.Decimal('1.0E+10000'); i = int(x)\", number=10)\n0.027457250020233914\n>>> timeit.timeit(setup=\"import decimal\", stmt=\"x = decimal.Decimal('1.0E+100000'); i = int(x)\", number=10)\n1.8902547920006327\n```\n\nThe decimal to int conversion should shortcut to a failure when there is no possibility of generating a real number, e.g. by examining the length of the substring after + or - (in conjunction with sys.set_int_max_str_digits or maybe some other setting).\n\n### CPython versions tested on:\n\n3.11, 3.12\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/roharvey","@type":"Person","name":"roharvey"},"datePublished":"2025-10-11T15:24:24Z","url":"https://github.com/python/cpython/issues/139957"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3fa494f4-c875-268f-590a-e81f7ee2c775 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F48:1F927B:1971636:218A8CD:6B020F5B |
| html-safe-nonce | 5aa1db700c0f467d39b8f08a7c0c395aa1efa94dcd0d263883625b69fa323776 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjQ4OjFGOTI3QjoxOTcxNjM2OjIxOEE4Q0Q6NkIwMjBGNUIiLCJ2aXNpdG9yX2lkIjoiNzM1MDk3MTg0NjEzODkyNDg5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c5ab5240c874397850a0ee86574ca161c19524e23ed59398e162afdac685d05d |
| hovercard-subject-tag | issue:3505985011 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139957/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f56942ed425561ee34c9318b777c76df169d7efb781319edfde4b4ac65fad5a2/python/cpython/issues/139957 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f56942ed425561ee34c9318b777c76df169d7efb781319edfde4b4ac65fad5a2/python/cpython/issues/139957 |
| og:image:alt | Bug report Bug description: Adding many digits to engineering notation causes cpython to work very hard trying to do the conversion, only for it to fail anyway. >>> x = decimal.Decimal('1.0E+10000'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | roharvey |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width