interval::operator/ returns the whole line for [-1,0] / [0,1] (strict is_neg(xu) in div_positive / div_negative)
还没有人认领这个 Issue。
评估
调研方向
该缺陷位于 include/boost/numeric/interval/detail/division.hpp 中的 div_positive(约第 78 行)和 div_negative(约第 113 行),其中 is_neg(xu) 判断会错误地分派上界恰好为零的被除数。请先编译 issue 中的复现代码,并确认 [-1,0] / [0,1] 返回整条实数轴。完成标准是:该情况返回 (-inf, 0],符号对称的情况返回 [0, +inf),并且在 test/mul.cpp 中添加了一个回归用例。
由索引模型根据 Issue 内容生成。
描述
Version: Boost 1.83.0 (headers only, g++ 13.3.0, -frounding-math). The relevant code in include/boost/numeric/interval/detail/division.hpp is unchanged on develop (a701c9dd22) and master.
What happens. The documentation of / says: "If the denominator contains zero (but not only zero), the result will be the smallest interval containing the set of division results; so one of its bound will be infinite, but it may not be the whole interval." For a numerator whose upper bound is exactly zero and a denominator with one zero endpoint, operator/ (and division_part1) return [-inf, +inf]:
[-1,0] / [0,1] = [-inf, inf] expected (-inf, 0]
[-1,0] / [-1,0] = [-inf, inf] expected [0, +inf)
[0,1] / [0,1] = [0, inf] (correct)
[0,1] / [-1,0] = [-inf, 0] (correct)
The result still encloses all quotients, so this is a loss of tightness relative to the documentation rather than an unsound result, and it breaks the sign symmetry between the third and first lines.
Reproducer (Boost headers only; g++ -std=c++17 -frounding-math repro.cpp && ./a.out):
#include <boost/numeric/interval.hpp>
#include <cstdio>
using I = boost::numeric::interval<double>;
static void show(const char* name, I x, I y) {
I r = x / y;
std::printf("%-16s = [%g, %g]\n", name, r.lower(), r.upper());
}
int main() {
show("[-1,0] / [0,1]", I(-1, 0), I(0, 1)); // expected (-inf, 0]
show("[-1,0] / [-1,0]", I(-1, 0), I(-1, 0)); // expected [0, +inf)
show("[0,1] / [0,1]", I(0, 1), I(0, 1)); // [0, +inf), correct
show("[0,1] / [-1,0]", I(0, 1), I(-1, 0)); // (-inf, 0], correct
}
Cause. div_positive(const interval&, const T& yu) (line 78) and div_negative(const interval&, const T& yl) (line 113) branch on is_neg(xu), i.e. xu < 0. When xu == 0 and xl < 0 this falls through to the is_neg(xl) branch, which is meant for a numerator containing zero in its interior, and returns the whole line. (The other two is_neg(xu) tests in the file, in div_non_zero and div_zero_part1, give correct results for xu == 0.)
Suggested fix. Replace is_neg(xu) with !is_pos(xu) in those two functions; x == [0,0] is already handled earlier by is_zero. I tested the patched header on 35,654 generated cases (boundary grid plus random, including signed zeros, subnormals, max and infinities) against an exact rational oracle: the 311 mismatching cases become correct, the other 35,343 are unchanged, and all 341 div vectors of the IEEE 1788 test suite (ITF1788) pass. To my reading the division tests in test/mul.cpp do not cover a numerator with an upper endpoint of 0. I'm happy to open a PR with the change and a regression test if that helps.
- 主要语言
- C++
- 星标
- 30
- 派生
- 49
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 7
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
boostorg/interval 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 44/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 10/100
-
Code behaves differently if compiled with MSVC vs GCC可能已有人在做 @reach2sayan 于 35 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 25/100
查看 boostorg/interval 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 82/100
psi29a/d2decomped#691 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
CachyOS/packageinstaller#144 ·
维护者通常 1 天内回复
-
prio:low type:bug
难度 2/5 1-3 小时 新手友好度 72/100
NatronGitHub/Natron#1638 ·
维护者通常 1 天内回复
-
documentation
难度 1/5 1 小时以内 新手友好度 82/100
TomerAberbach/profiler-md#951 ·
维护者通常 1 天内回复
-
area:readers low-priority
难度 2/5 1-3 小时 新手友好度 62/100
NatronGitHub/openfx-arena#214 ·
维护者通常 1 天内回复