interval::operator/ returns the whole line for [-1,0] / [0,1] (strict is_neg(xu) in div_positive / div_negative)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
Hướng nghiên cứu
Lỗi nằm trong include/boost/numeric/interval/detail/division.hpp, ở div_positive (khoảng dòng 78) và div_negative (khoảng dòng 113), nơi phép kiểm tra is_neg(xu) định tuyến sai một tử số có cận trên đúng bằng không. Hãy bắt đầu bằng cách biên dịch đoạn tái hiện trong issue và kiểm tra rằng [-1,0] / [0,1] trả về toàn bộ đường thẳng. Hoàn thành khi trường hợp đó trả về (-inf, 0], trường hợp đối xứng dấu trả về [0, +inf), và một trường hợp hồi quy được thêm vào test/mul.cpp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C++
- Star
- 30
- Fork
- 49
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của boostorg/interval
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 44/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Emscripten compilation issueĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
-
Code behaves differently if compiled with MSVC vs GCCCó thể đã có người làm @reach2sayan đã nhận 35 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của boostorg/interval
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
psi29a/d2decomped#691 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
CachyOS/packageinstaller#144 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
prio:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NatronGitHub/Natron#1638 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
TomerAberbach/profiler-md#951 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:readers low-priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
NatronGitHub/openfx-arena#214 ·
Maintainer thường phản hồi trong vòng 1 ngày