Is generate_canonical output consistent across platforms?

The C ++ standard pretty accurately points to [rand.util.canonical] just how the template function works std::generate_canonical(although it only represents pseudocode, not C ++ code).

Is it the intention of spec authors that on different platforms where mathematics RealTypeworks the same and deterministic URNG, which gives the same outputs on two platforms, which std::generate_canonicalgives identical outputs as well?

This is due to similar questions, such as Is 1.0 a valid exit from std :: generate_canonical? - prose states that 1.0 is excluded, but the algorithm that they give in pseudo-code includes it as an output sometimes for some combinations of RealTypeand URNG.

This differs from the random number distribution functions discussed, for example, how C ++ 11 random number distribution is not compatible between platforms - what are the alternatives? ; the standard `` 'not' '' indicates how, for example, a normal distribution is generated, only its properties

I did not find DR where this is discussed, and the wording of the standard is superficially identical in C ++ 11, C ++ 14 and C ++ 17 projects. I have easy access.

+4
source share
1 answer

Difficulties arising in a related issue indicate the main problem with consistency: rounding mode. The clear intention of the mathematical definition generate_canonicalin the standard is that the URNG should be called several times, each of which creates a non-overlapping block of entropy to fill the result; it will be fully harmonized between platforms. The problem is that it does not indicate what to do with the extra bits below LSB. Depending on the rounding mode and the summation order, they can be rounded up, spilling into the next block (which allows the result of 1.0).

- " ... , ". , , 1.0, , ( 1-eps , 1-2 * eps). " ". , , , generate_canonical , .

, , 1.0, , . , , , URNG independent_bits_engine, bits, .

+1

Source: https://habr.com/ru/post/1671823/


All Articles