https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118841
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- Maybe like this: --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -3351,12 +3351,17 @@ namespace __detail static_assert(std::is_floating_point<_RealType>::value, "template argument must be a floating point type"); + using _MaxRealType + = __conditional_t<(std::numeric_limits<_RealType>::digits + <= std::numeric_limits<double>::digits), + double, long double>; const size_t __b = std::min(static_cast<size_t>(std::numeric_limits<_RealType>::digits), __bits); - const long double __r = static_cast<long double>(__urng.max()) - - static_cast<long double>(__urng.min()) + 1.0L; - const size_t __log2r = std::log(__r) / std::log(2.0L); + const _MaxRealType __r = static_cast<_MaxRealType>(__urng.max()) + - static_cast<_MaxRealType>(__urng.min()) + + 1.0L; + const size_t __log2r = std::log(__r) / std::log((_MaxRealType)2.0); const size_t __m = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r); _RealType __ret;