[Bug libstdc++/80137] [6/7 Regression] std::generate_canonical calls its generator a non-constant number of times

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 27 09:43:00 GMT 2017


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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We need to handle targets without C99's nextafter, but maybe this would be OK:

      if (__builtin_expect(__ret >= _RealType(1), 0))
        {
#if _GLIBCXX_USE_C99_MATH_TR1
          __ret = std::nextafter(_RealType(1), _RealType(0));
#else
          __ret = _RealType(0);
#endif
        }

If we reach 1.0 it's because we're rounding up or to nearest, and so returning
zero in that case would counteract the decreased probability of getting zero
otherwise.


More information about the Gcc-bugs mailing list