Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

nth_root does not restore the rounding mode and can return an upper bound below the true root

Cerrado Apto para principiantes
#54 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
data

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.

  1. The rounding mode is left changed when the function returns.
  2. 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 -O0 and -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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de boostorg/interval

Todos los issues de boostorg/interval

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.