Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Linear congruential generator produces different values than gcc and msvc #33178

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR34206
Status NEW
Importance P normal
Reported by Dirk Reinbach (dirk.reinbach@gmail.com)
Reported on 2017-08-16 02:10:50 -0700
Last modified on 2017-08-16 02:57:46 -0700
Version 5.0
Hardware Macintosh MacOS X
CC dirk.reinbach@gmail.com, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
Fixed by commit(s)
Attachments file_34206.txt (215 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 18991
linear_congruential_engine test

To my understanding the C++ standard does not mandate the algorithms for random
number distributions but it does mandate the algorithms for random number
generators like linear_congruential_engine. So one should be able to generate
consistent random values across all platforms/compilers.

However, i stumbled upon inconsistent values between various compilers and
verified this observation with online compilers. I am not sure which compiler
is right, but at least gcc and msvc agree on their results.

Please find attached a code snippet to reproduce the observed behavior.

I put this code snippet into Rextester:

  http://rextester.com/l/cpp_online_compiler_gcc (g++ 5.4.0)
  http://rextester.com/l/cpp_online_compiler_clang (clang 3.8.0)
  http://rextester.com/l/cpp_online_compiler_visual (Microsoft 19.00.23506 for x86)

Output:

  25214903928 206026503483683 245470556921330 (gcc)
  25214903928 18444698300399350051 8295313034219953650 (clang)
  25214903928 206026503483683 245470556921330 (msvc)

I also put this code snippet into a Compiler Explorer project. It illustrates
that Clang 3.8 and Clang trunk produce exactly the same code/values.

  https://godbolt.org/g/rBSjaS

A possibly somehow related issue:

  https://bugs.llvm.org/show_bug.cgi?id=27839
Quuxplusone commented 7 years ago

Attached file_34206.txt (215 bytes, text/plain): linear_congruential_engine test