diff --git a/include/random b/include/random index c83db12af..6c36e8c01 100644 --- a/include/random +++ b/include/random @@ -3997,7 +3997,18 @@ public: {return !(__x == __y);} }; +#ifndef _LIBCPP_MSVCRT extern "C" double lgamma_r(double, int *); +#endif + +inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { +#if defined(_LIBCPP_MSVCRT) + return lgamma(__d); +#else + int __sign; + return lgamma_r(__d, &__sign); +#endif +} template binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) @@ -4005,11 +4016,10 @@ binomial_distribution<_IntType>::param_type::param_type(const result_type __t, c { if (0 < __p_ && __p_ < 1) { - int __sign; __r0_ = static_cast((__t_ + 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_) + + __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - + __libcpp_lgamma(__r0_ + 1.) - + __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + (__t_ - __r0_) * _VSTD::log(1 - __p_)); __odds_ratio_ = __p_ / (1 - __p_); }