template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
bool __big_enough = (!(__m & (__m - 1))
|| (_Tp(-1) - __c) / __a >= __m - 1),
- bool __schrage_ok = __a != 0 && __m % __a < __m / __a>
+ bool __schrage_ok = __m % __a < __m / __a>
struct _Mod
{
typedef typename _Select_uint_least_t<std::__lg(__a)
template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
inline _Tp
__mod(_Tp __x)
- { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
+ {
+ if _GLIBCXX17_CONSTEXPR (__a == 0)
+ return __c;
+ else
+ {
+ // _Mod must not be instantiated with a == 0
+ constexpr _Tp __a1 = __a ? __a : 1;
+ return _Mod<_Tp, __m, __a1, __c>::__calc(__x);
+ }
+ }
/*
* An adaptor class for converting the output of any Generator into
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// { dg-do compile { target c++11 } }
+// { dg-do run { target c++11 } }
#include <random>
+#include <testsuite_hooks.h>
-unsigned
+void
test01()
{
std::linear_congruential_engine<unsigned, 0, 0, 0> l;
- return l(); // this used to result in divide by zero
+ auto r = l(); // this used to result in divide by zero
+ VERIFY( r == 0 );
+ l.seed(2);
+ r = l();
+ VERIFY( r == 0 );
+ VERIFY( l() == 0 );
+}
+
+void
+test02()
+{
+ std::linear_congruential_engine<unsigned, 0, 0, 3> l;
+ auto r = l(); // this used to result in a different divide by zero
+ VERIFY( r == 0 );
+ l.seed(2);
+ r = l();
+ VERIFY( r == 0 );
+ VERIFY( l() == 0 );
+}
+
+void
+test03()
+{
+ std::linear_congruential_engine<unsigned, 0, 2, 3> l;
+ auto r = l();
+ VERIFY( r == 2 );
+ l.seed(4);
+ r = l();
+ VERIFY( r == 2 );
+ VERIFY( l() == 2 );
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
}
auto x = std::generate_canonical<std::size_t,
std::numeric_limits<std::size_t>::digits>(urng);
-// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 158 }
+// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 167 }
// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3281 }