This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fix operator precedence in _ShiftMin1.
Smith-Rowland, Edward M wrote:
All,
The following fixes a bonehead mistake in operator precedence in
the _ShiftMin1 tool used by mersenne_twister_engine and others.
I think this might be obvious and may be the source of other mistakes.
I am bootstrapping and regtesting now but this might be obvious.
Ed
All,
There was one mistake left:
Change this:
__gnu_cxx::__numeric_traits<_UIntType>::max;
to this:
__gnu_cxx::__numeric_traits<_UIntType>::__max;
Add two underscores to max.
Here is the new patchlet.
This doesn't really have much to do with 39629. Sorry for the noise.
Ed
Index: include/bits/random.h
===================================================================
--- include/bits/random.h (revision 145501)
+++ include/bits/random.h (working copy)
@@ -75,17 +75,18 @@
// XXX need constexpr
template<typename _UIntType, size_t __w,
- bool = __w <static_cast<size_t>
- (std::numeric_limits<_UIntType>::digits)>
+ bool = __w < static_cast<size_t>
+ (std::numeric_limits<_UIntType>::digits)>
struct _ShiftMin1
- {
+ {
static const _UIntType __value =
__gnu_cxx::__numeric_traits<_UIntType>::__max;
};
template<typename _UIntType, size_t __w>
struct _ShiftMin1<_UIntType, __w, true>
- { static const _UIntType __value = _UIntType(1) << __w - _UIntType(1); };
+ { static const _UIntType __value
+ = (_UIntType(1) << __w) - _UIntType(1); };
template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
struct _Mod;
@@ -389,7 +390,7 @@
{
__glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
- static_assert(__m >= 1U,
+ static_assert(__m >= 1U,
"mersenne_twister_engine template arguments out of bounds");
static_assert(__n >= __m,
"mersenne_twister_engine template arguments out of bounds");
@@ -403,18 +404,15 @@
"mersenne_twister_engine template arguments out of bounds");
static_assert(__w >= __l,
"mersenne_twister_engine template arguments out of bounds");
- static_assert(__w <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
+ static_assert(__w
+ <= static_cast<size_t>(numeric_limits<_UIntType>::digits),
"mersenne_twister_engine template arguments out of bounds");
-
-#if 0
- // XXX
static_assert(__a <= __detail::_ShiftMin1<_UIntType, __w>::__value,
"mersenne_twister_engine template arguments out of bounds");
static_assert(__b <= __detail::_ShiftMin1<_UIntType, __w>::__value,
"mersenne_twister_engine template arguments out of bounds");
static_assert(__c <= __detail::_ShiftMin1<_UIntType, __w>::__value,
"mersenne_twister_engine template arguments out of bounds");
-#endif
public:
/** The type of the generated random value. */
Index: testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc
===================================================================
--- testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc (revision 145501)
+++ testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc (working copy)
@@ -40,7 +40,7 @@
0xefc60000ul, 18, 1812433253ul> x;
VERIFY( x.min() == 0 );
- // XXX VERIFY( x.max() == 4294967295ul);
+ VERIFY( x.max() == 4294967295ul);
VERIFY( x() == 3499211612ul );
}