-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as duplicate of#90716
Closed as duplicate of#90716
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
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 last):
File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
But the time it takes goes up when you add extra digits. It appears to be unbounded.
>>> timeit.timeit(setup="import decimal", stmt="x = decimal.Decimal('1.0E+10000'); i = int(x)", number=10)
0.027457250020233914
>>> timeit.timeit(setup="import decimal", stmt="x = decimal.Decimal('1.0E+100000'); i = int(x)", number=10)
1.8902547920006327
The 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).
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
macOS
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement