Bug: num_digits_fast() returns incorrect digit count for large integers
Los mantenedores suelen responder en 1 día
@SaifAli-S ya está trabajando en esto.
Desde el 13/11/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 25/100
Línea de trabajo
The bug is in num_digits_fast() in maths/number_of_digits.py, which estimates the digit count with math.floor(math.log(abs(n), 10) + 1). Run the reproduction with n = 10**16 - 1 and compare against num_digits() and len(str(n)). Done means num_digits_fast() agrees with both at powers of ten and their neighbours. Pull request #15754 is already open against this issue, so check it before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Repository commit
30507bbe41397065728167fb09aa820f9fce8dc7
Python version (python --version)
Python 3.14.4
Dependencies version (pip freeze)
aptdaemon==2.0.2
attrs==25.4.0
autocommand==2.2.2
babel==2.17.0
bcc==0.35.0
bcrypt==5.0.0
blinker==1.9.0
Brlapi==0.8.6
certifi==2026.1.4
chardet==5.2.0
click==8.1.8
command-not-found==0.3
configobj==5.0.9
cryptography==46.0.5
cupshelpers==1.0
dasbus==1.7
dbus-python==1.4.0
defer==1.0.6
distro==1.9.0
distro-info==1.15
gyp-next==0.16.2
httplib2==0.22.0
idna==3.11
inflect==7.5.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
jaraco.text==4.0.0
Jinja2==3.1.6
jsonpatch==1.32
jsonpointer==2.4
jsonschema==4.19.2
jsonschema-specifications==2023.12.1
language-selector==0.1
launchpadlib==2.1.0
lazr.restfulclient==0.14.6
lazr.uri==1.0.6
libpass==1.9.3
linkify-it-py==2.0.3
louis==3.36.0
markdown-it-py==3.0.0
MarkupSafe==3.0.3
mdurl==0.1.2
more-itertools==10.8.0
netaddr==1.3.0
oauthlib==3.3.1
olefile==0.47
packaging==26.0
pexpect==4.9.0
pillow==12.1.1
pip==25.1.1
psutil==7.1.0
ptyprocess==0.7.0
pycairo==1.27.0
pycups==2.0.4
Pygments==2.19.2
PyGObject==3.56.2
PyJWT==2.10.1
pyparsing==3.3.2
pyserial==3.5
python-apt==3.1.0+ubuntu1.1
python-debian==1.0.1+ubuntu2
pyxdg==0.28
PyYAML==6.0.3
referencing==0.36.2
requests==2.32.5
rich==13.9.4
rpds-py==0.27.1
screen-resolution-extra==0.0.0
setproctitle==1.3.7
setuptools==78.1.1
systemd-python==235
typeguard==4.4.4
typing_extensions==4.15.0
ubuntu-drivers-common==0.0.0
ubuntu-pro-client==8001
uc-micro-py==1.0.3
ufw==0.36.2
unattended-upgrades==0.1
urllib3==2.6.3
wadllib==2.0.0
wheel==0.46.3
xdg==5
xkit==0.0.0
zipp==3.23.0
Expected behavior
num_digits_fast(9999999999999999) should return 16,
because the input contains exactly 16 decimal digits.
It should agree with num_digits() and len(str(n)).
Actual behavior
Bug reproduction
The num_digits_fast() function in maths/number_of_digits.py incorrectly counts the digits of certain large integers.
Steps to reproduce:
from maths.number_of_digits import num_digits_fast, num_digits
n = 10**16 - 1
print("Expected:", len(str(n)))
print("Actual:", num_digits_fast(n))
print("Standard implementation:", num_digits(n))
Observed output:
Expected: 16
Actual: 17
Standard implementation: 16
Possible cause
The function uses:
math.floor(math.log(abs(n), 10) + 1)
Floating-point rounding near powers of ten can produce an off-by-one error.
Suggested improvement
Consider using exact integer arithmetic or validating the logarithmic estimate against integer powers of ten.
A regression test using 10**16 - 1 would help prevent this issue from recurring.
Environment
- Python: 3.14.4
- Repository commit:
30507bbe41397065728167fb09aa820f9fce8dc7 - Third-party dependencies required: None
Related issue: #2220 introduced the motivation for the faster implementation through PR #2221. This report concerns correctness, not performance.
- Lenguaje dominante
- Python
- Estrellas
- 226k
- Forks
- 51.3k
- Merge medio
- 8 h 58 min
- PR fusionados (30 d)
- 4
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TheAlgorithms/Python
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
TheAlgorithms/Python#15763 ·
Los mantenedores suelen responder en 1 día
-
binomial_distribution overflows at 171 trials even when the result is representablePosiblemente ocupada @landfvit la tomó hace 19 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
TheAlgorithms/Python#15656 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowErrorPosiblemente ocupada @trleo la tomó hace 19 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
TheAlgorithms/Python#15655 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crashPosiblemente ocupada @Nate-br la tomó hace 21 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
TheAlgorithms/Python#15636 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Posiblemente ocupada @mohammedanasnakhuda la tomó hace 21 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
TheAlgorithms/Python#15634 ·
Los mantenedores suelen responder en 1 día
Todos los issues de TheAlgorithms/Python
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
-
Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
pandas-dev/pandas#72163 ·
Los mantenedores suelen responder en 2 días
-
LightFM prepare_test_df ignores mapping values and silently mislabels evaluation pairsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
recommenders-team/recommenders#2480 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
521xueweihan/HelloGitHub#4385 ·
-
🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pdm-project/pdm#4012 ·
Los mantenedores suelen responder en 1 día