Skip to content

Commit 6b55711

Browse files
committed
address review
1 parent 23494fb commit 6b55711

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎Lib/_pydecimal.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,9 @@ def _tento(n):
465465
def _is_less_than_pow10a_use_str(q, a):
466466
"""Try to efficiently check len(str(q)) <= a, or equivalently q < 10**a.
467467
468-
If it is not possible to efficiently compute len(str(q)),
469-
this explicitly compute str(q) instead.
468+
If it is not possible to efficiently compute the comparison, str(q) is
469+
explicitly computed. str(q) may also be computed for cases that cannot
470+
be optimized.
470471
471472
Return (len(str(q)) <= a, None) or (len(str(q)) <= a, str(q)).
472473
"""
@@ -485,8 +486,12 @@ def _is_less_than_pow10a_use_str(q, a):
485486

486487
# assert q > 10 ** a
487488
return False, None
488-
# Handles other cases due to floating point precision loss
489-
# when computing _LOG_10_BASE_2_LO and _LOG_10_BASE_2_HI.
489+
# Handle cases that fail due to floating point precision loss
490+
# when computing _LOG_10_BASE_2_LO and _LOG_10_BASE_2_HI, or
491+
# that cannot be distinguished with (q.bit_length(), a) only.
492+
#
493+
# For instance, (q1, a) = (95, 2) and (q2, a) = (105, a) produce
494+
# different results but q1.bit_length() == q2.bit_length() == 7.
490495
str_q = str(q) # can raise a ValueError
491496
is_valid = len(str_q) <= a
492497
return is_valid, str_q

0 commit comments

Comments
 (0)