Boost.Random subtract_with_carry doesn't like m == numeric_limits<result_type>::digits

Hello, Boost folks. I found a bug in subtract_with_carry_engine while fixing a bug in MSVC++'s implementation of the same, where m == numeric_limits<result_type>::digits. Consider the following: #include <stdlib.h> #include <stdio.h> #ifdef USE_BOOST #include <boost/random/subtract_with_carry.hpp> using namespace boost::random; #else #include <random> using namespace std; #endif template <typename Engine> typename Engine::result_type run_10k(Engine engine) { for (int i = 0; i < 9999; ++i) { engine(); } return engine(); } int main() { subtract_with_carry_engine<unsigned long long, 64, 10, 24> ull_swc; ull_swc.seed(0x12341234'00000000); printf("0x%016llX\n", run_10k(ull_swc)); } MSVC++ said: 0xFCF0A4776BA0A6A8 Libstdc++ says: 0x01316AEA3646F686 Libc++ says: 0x01316AEA3646F686 Boost 1.60.0/libc++ + Clang says: 0x69E18848FE1BD36D Boost 1.60.0/libstdc++ + g++ says: 0x1DD6C263C41EEED0 MSVC++'s bug was that we did the underflow check incorrectly resulting in the carry bit always being set if m == numeric_limits<result_type>::digits. I fixed that and MSVC++ will agree with libstdc++ and libc++ in the next update; but boost's behavior here is still strange. Hope that helps, Billy Robert O'Neal III SDE II - Visual C++ Libraries bion@microsoft.com

AMDG On 05/10/2016 01:43 PM, Billy O'Neal (VC LIBS) wrote:
MSVC++ said: 0xFCF0A4776BA0A6A8 Libstdc++ says: 0x01316AEA3646F686 Libc++ says: 0x01316AEA3646F686 Boost 1.60.0/libc++ + Clang says: 0x69E18848FE1BD36D Boost 1.60.0/libstdc++ + g++ says: 0x1DD6C263C41EEED0
MSVC++'s bug was that we did the underflow check incorrectly resulting in the carry bit always being set if m == numeric_limits<result_type>::digits. I fixed that and MSVC++ will agree with libstdc++ and libc++ in the next update; but boost's behavior here is still strange.
The first problem is this: BOOST_STATIC_CONSTANT(result_type, modulus = (result_type(1) << w)); which is almost certainly the cause of the different results for clang vs. g++. In Christ, Steven Watanabe
participants (2)
-
Billy O'Neal (VC LIBS)
-
Steven Watanabe