File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -549,13 +549,32 @@ dimension(dim)
549549 maxVal.resize (L);
550550 double norm;
551551 std::normal_distribution<double > realDist (0.0 , 1.0 );
552+
553+ // TODO: Test this with MacOS and others
554+ #ifdef __GLIBCXX__
555+ # define getRandomValue () realDist(rg)
556+ #else
557+ // The order of the values in MSVC and LIBCPP is different.
558+ // To have the same results, we cache values pair-wise,
559+ // then return them in swapped order to put them in the same order.
560+ size_t i = 0 ;
561+ float vals[2 ] = { };
562+ auto getRandomValue = [&]() -> float {
563+ if (! (i % 2 )) {
564+ vals[0 ] = realDist (rg);
565+ vals[1 ] = realDist (rg);
566+ }
567+ return vals[++i % 2 ];
568+ };
569+ #endif
570+
552571 for (int i = 0 ; i < L; i++)
553572 {
554573 maxVal[i] = -1 ;
555574 norm = 0.0 ;
556575 for (int j = 0 ; j < dimension; j++)
557576 {
558- rndpoint[j] = realDist (rg );
577+ rndpoint[j] = getRandomValue ( );
559578 norm += rndpoint[j] * rndpoint[j];
560579 }
561580 norm = std::sqrt (norm);
You can’t perform that action at this time.
0 commit comments