nth_root does not restore the rounding mode and can return an upper bound below the true root
まだ誰も着手していません。
評価
調査の方向性
boost/numeric/interval/arith2.hpp の nth_root から始め、同じファイル内で既に保護された型のために丸めオブジェクトを作成している fmod、cos、tan と比較してください。再現プログラムの出力を読んでください。呼び出し後に丸めモードが変更されており、(0, 1) の一部の入力では上限が sqrt(x) を下回っています。関数が丸めモードを復元し、境界が真の平方根を含むことを、再現プログラムと既存の区間テストで確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C++
- スター
- 31
- フォーク
- 48
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/interval のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
boostorg/interval の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Mac mini M6 (16 GB): Q2_0 streaming works - measured 11.7->27.2 tok/s + arena fix for sub-32 GB Macsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
champion good first issue remake source/qq
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
metasequoiaime/msime-windows#1025 ·
メンテナーはふだん 1 日以内に返信
-
backlog bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
EchoTools/nevr-runtime#653 ·
メンテナーはふだん 1 日以内に返信
-
`--fail-require-skip` never fires: run_tests.py searches stdout, but the unittest binary writes the skip summary to stderr対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信