nth_root does not restore the rounding mode and can return an upper bound below the true root
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia in boost/numeric/interval/arith2.hpp da nth_root e confrontalo con fmod, cos e tan nello stesso file, che creano già un oggetto di arrotondamento per il tipo protetto. Leggi l'output del reproducer: la modalità di arrotondamento viene modificata dopo la chiamata, e il limite superiore è inferiore a sqrt(x) per alcuni input in (0, 1). Il lavoro è completo quando la funzione ripristina la modalità di arrotondamento e i limiti contengono la radice vera, verificato con il reproducer e con i test esistenti sugli intervalli.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 31
- Fork
- 48
- Merge medio
- 2g 5m
- PR unite (30g)
- 4
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/interval
-
Emscripten compilation issueAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Tutte le issue di boostorg/interval
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
leanprover/lean4#15683 ·
I maintainer di solito rispondono entro 1 giorno
-
llvm.memcpy with destination align but no source align asserts "Missed Source alignment!"Forse già presa @pvelesko l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
KhronosGroup/SPIRV-LLVM-Translator#4093 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
SIMQ silently truncates multi-query batch search to the first queryForse già presa @LHT129 l’ha presa oggi. Apertakind/bug module/index needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
antgroup/vsag#3080 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno