diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-05-04 16:36:39 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-05-04 16:36:39 +0000 |
commit | d6d22fe91606365fdc734bec94862ee13fd39f67 (patch) | |
tree | 3f0add9e9c8c4d09b03772da9dcf3a82b954ed73 | |
parent | ba701469a9d579bec3250b8bd47df4d3caf1ea7d (diff) | |
download | bcm5719-llvm-d6d22fe91606365fdc734bec94862ee13fd39f67.tar.gz bcm5719-llvm-d6d22fe91606365fdc734bec94862ee13fd39f67.zip |
Use lgamma_r instead of lgamma in binomial_distribution, because freakin' POSIX took a perfectly fine call and made it not thread safe.
llvm-svn: 302168
-rw-r--r-- | libcxx/include/random | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libcxx/include/random b/libcxx/include/random index 83fff90a417..c83db12af30 100644 --- a/libcxx/include/random +++ b/libcxx/include/random @@ -3997,16 +3997,20 @@ public: {return !(__x == __y);} }; +extern "C" double lgamma_r(double, int *); + template<class _IntType> -binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) +binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) : __t_(__t), __p_(__p) { if (0 < __p_ && __p_ < 1) { + int __sign; __r0_ = static_cast<result_type>((__t_ + 1) * __p_); - __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) - - _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + - (__t_ - __r0_) * _VSTD::log(1 - __p_)); + __pr_ = _VSTD::exp(lgamma_r(__t_ + 1., &__sign) - + lgamma_r(__r0_ + 1., &__sign) - + lgamma_r(__t_ - __r0_ + 1., &__sign) + __r0_ * _VSTD::log(__p_) + + (__t_ - __r0_) * _VSTD::log(1 - __p_)); __odds_ratio_ = __p_ / (1 - __p_); } } |