emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.79k stars 3.3k forks source link

<random> linear_congruential_engine and subtract_with_carry_engine not consistent with other platforms #3712

Closed iboB closed 9 years ago

iboB commented 9 years ago

Simple repro case:

ranlux24 rl(1234);
for(int i=0; i<5; ++i)
    cout << rl() << endl;
minstd_rand mr(5678);
for(int i=0; i<5; ++i)
    cout << mr() << endl;

I get the same numbers on Windows with msvc12 and Linux with gcc 4.9.2 but different ones in the browser with Emscripten.

Only the Mersenne Twister engine seems to produce the same numbers on all platforms.

edit: In case it's not clear. I do get the same numbers on different runs in the browser. The seed works. What I don't get are the same numbers across all platforms.

kripken commented 9 years ago

Should they be the same across platforms? What is the relevant spec?

iboB commented 9 years ago

From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3551.pdf

For knowledgable users, the library provides nine additional aliases for pre-configured engine types of known good quality.12 These types span a wide spectrum of trade-offs in performance and size. Among other characteristics, the C++11 standard requires that these engines produce bit-for-bit identical results across implementations

iboB commented 9 years ago

Also, I just tested this and I get the exact same values as the ones on Windows msvc and Linux gcc, on Mac OS X with clang 3.6.0 (Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)), so it doesn't seem to be a libc++ problem

iboB commented 9 years ago

Well, I cannot reproduce this 1.34.6. I could in 1.34.1. I have no Idea what might have caused this...

kripken commented 9 years ago

It's possible a libc update since 1.34.1 made a difference.