Box-Muller - normal distributed random numbers
Hi, I wonder why _cached_rho is calclulated this way: sqrt(-result_type(2) * log(result_type(1)-_r2)); in normal_distribution.hpp:70 and not sqrt(-result_type(2) * log(_r2)); So I don't understand why there is "result_type(1) - _r2" instead of just "_r2". Cheers! matthias PS.: I hope this was not a stupid question, if so please forgive me as I am just a newbie.
AMDG Matthias Fuchs wrote:
I wonder why _cached_rho is calclulated this way:
sqrt(-result_type(2) * log(result_type(1)-_r2));
in normal_distribution.hpp:70 and not
sqrt(-result_type(2) * log(_r2));
So I don't understand why there is "result_type(1) - _r2" instead of just "_r2".
_r2 is in the range [0, 1). log(0) is a bad idea, so the algorithm uses 1-_r2 to flip the range to (0, 1]. In Christ, Steven Watanabe
participants (2)
-
Matthias Fuchs
-
Steven Watanabe