https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125548

            Bug ID: 125548
           Summary: piecewise_linear_distribution(nw, xmin, xmax, fw)
                    invokes fw with incorrect values
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkaminsk at gcc dot gnu.org
  Target Milestone: ---

The piecewise_linear_distribution(nw, xmin, xmax, fw) constructor invokes the
fw with incorrect values. For example with following code:
void test(int n)
{
  std::cout << "Test for value " << n << std::endl;
  const double step = 1.0/n;
  auto test = [step, val = 0.0] (double v) mutable {
    std::cout << v << " " << val << std::endl;
    val += step;
    return val;
  };

  std::piecewise_linear_distribution<> d(n, 0.0, 1.0, test);
}
The invocation of test(4) prints:
0.25 0
0.5 0.25
0.75 0.5
1 0.75
1.25 1
While standard defines (and libc++ and MVSSTL produces):
0 0
0.25 0.25
0.5 0.5
0.75 0.75
1 1

The behavior for test(1) was fixed by r17-509-g7bed7d9276c11b,
GCC-16 and eariel produces
1 0
2 1


See https://godbolt.org/z/qn84P67Md.

Reply via email to