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::digits. Consider the following:
#include
#include
#ifdef USE_BOOST
#include
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 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::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