nth_root does not restore the rounding mode and can return an upper bound below the true root
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
Línea de trabajo
Empieza en boost/numeric/interval/arith2.hpp en nth_root y compáralo con fmod, cos y tan en el mismo archivo, que ya crean un objeto de redondeo para el tipo protegido. Lee la salida del reproductor: el modo de redondeo se cambia después de la llamada, y el límite superior queda por debajo de sqrt(x) para algunas entradas en (0, 1). Está terminado cuando la función restaura el modo de redondeo y los límites contienen la raíz verdadera, comprobado con el reproductor y las pruebas de intervalos existentes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
nth_root (in boost/numeric/interval/arith2.hpp) works in the unprotected interval type but never creates a rounding object for the protected type, unlike fmod, cos and tan. This has two effects when it is called from code running in round-to-nearest.
- The rounding mode is left changed when the function returns.
- For some inputs in (0, 1) the upper bound is below the true root, so the result does not contain it.
Reproducer
Godbolt (GCC trunk, Boost 1.92.0, -std=c++03 -frounding-math)
It calls nth_root(interval<double>(0.80166573794976181), 2) from round-to-nearest, reads the rounding mode before and after, and computes upper^2 - x exactly.
Output (the same on develop at 3957843; nth_root is identical in Boost 1.92.0 and develop):
rounding mode: to nearest before, changed after
nth_root([0.80166573794976181], 2) = [0.89535788260882665, 0.89535788260882687]
upper^2 - x = -1.31841e-17
upper^2 - x is negative, so the upper bound is below sqrt(x).
Tested with
x86-64 Linux, glibc 2.39, double, always with -frounding-math:
- GCC 13.3:
-O0,-O2,-O3, C++03 and C++17,-O2 -mfma,-O2 -mfpmath=387,-m32 -O2 - Clang 18.1.3:
-O0,-O2,-O2 -mfma
All give the result above. It also happens at -O0, so it does not depend on optimization.
How often
I ran 1.6 million pairs (x, k), with x uniform in (0, 1) and k = 2…9, and checked each bound exactly with MPFR. 1,321 upper bounds were below the true root. No lower bound was
wrong. The rounding mode was changed after every call. For x in (1, 1000) no bound was wrong, but the mode was still changed after every call.
No compiler flag changes these counts. Tried on top of -frounding-math:
- GCC 13.3:
-O0,-O2,-ftrapping-math,-fsignaling-nans,-ffloat-store,-fno-inline,-ffp-contract=off,-mfpmath=387,#pragma STDC FENV_ACCESS ON - Clang 18.1.3:
-O2,-ftrapping-math,-ffp-exception-behavior=strict,-ffp-model=strict(at-O0and-O2),#pragma STDC FENV_ACCESS ON
With the rounding mode set to upward before the call, or with the caller holding a rounding object (interval<double>::traits_type::rounding rnd;) around the call, there were
no wrong bounds.
- Lenguaje dominante
- C++
- Estrellas
- 31
- Forks
- 48
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 6
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 boostorg/interval
-
Emscripten compilation issueAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
Todos los issues de boostorg/interval
Issues similares
-
agent:Windows bug code-review LOW testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día
-
[Cleanup] Include the public header in work_split.cppPosiblemente ocupada @blozano-tt la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
tenstorrent/tt-metal#60850 ·
Los mantenedores suelen responder en 1 día
-
Build: the CUDA backend fails without cuDNN instead of skipping the cuDNN shim (as the cuDF shim does)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
beehive-lab/TornadoVM#1248 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
SimVascular/svZeroDSolver#253 ·
-
bug Filter
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
BlueQuartzSoftware/simplnx#1825 ·
Los mantenedores suelen responder en 3 días