Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130167: Improve speed of _pydecimal._all_zeros and _pydecimal._exact_half by replacing re #132065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Prev Previous commit
simplified and sped up exact_half
  • Loading branch information
Marius-Juston committed Apr 4, 2025
commit faae133bbd3773f1686fcb909593b6f75a32eddd
11 changes: 10 additions & 1 deletion 11 Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6089,7 +6089,16 @@ def _all_zeros(d_int, prec=0):

# Checks for regex 50*$
def _exact_half(d_int, prec=0):
return len(d_int) >= prec + 1 and d_int[prec] == '5' and d_int.endswith( (len(d_int) - prec - 1) * '0')
len_d = len(d_int)
i = prec + 1

if len_d >= i and d_int[prec] == '5':
while i < len_d:
if d_int[i] != '0':
return False
i += 1
return True
return False

##### PEP3101 support functions ##############################################
# The functions in this section have little to do with the Decimal
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.