<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylVMFymzAQ_Rq4aMyAMNgcOMRx0umlhzTtlRGwgBohMZKw47_vCoxTT5JOPWUESNp9u29XuypVfcp_GC5bYjsgjRJCHd1KM9kC8dLQS3YrY2svvsMhxx40rwrBe26NF98_evHDLOrZq0e3Hs08ek9uBGToB31r5-8CHSXHrb7QwERRc2M1L0fLlVysIOaIK7qx-NcvZNBqAC1OhMmaMHFkJ0NakKCZBeNMc9k40IGJEUxAvHDvhXfnLwY6j2lpoR8EwtBVJZgxpHhCFs-nAZzjT1R-PH37chFzKbiEsyriJOuB_C2kKw9TAjSYUdjCoWc7t8FdMphVeknydiZIU1IUrTukSkljycA062cnk2hwynNONrt5QvDRYEctiTNTDEE5GyUrBwjY2zle9N3j0TtS_Pz-vJ8JLWdRVEwqySsmrngjo3fV8j6qmreT6GFi0n7gc3fFKd4twew_PGlkUY1iqZCb6hajv7EzXMV2vOqIOoBusNNcFSa7ahg0NKBBVuAle1TurB2MQ9NHHCCDP1WCSvW4e8QXt_F79o0z7Np6En5eKsgbK_PFEKuw5blxBAaGtfKR546JgOmq4wcwKzUia0xU0OhZtApjuqWbbI3LWlXIQlpnf47RtaMymFdGGv46tzeNoyxaRwH5is0DTn--eZglRomJIOkZdrAwipSA0Mu2w098uTEjBH6dx3UWZ8xno-2UznulayYt-KMW-XUUWDHdWJ7TJsRh-a2Q4i-okPPjZNTgJKFZmvpdvoljSCCJIF5DSbdsU5f1epsmTU0rFrKtL1gJwuSYPY9SwUtM_24aFBPp_z8FntOQ0jAK42gbb-IsoJt1FDdplaZRw2gSe-sQesZF4OwESre-zieT5dgaFAo8dfMmxCuKtxJgYowMLbcCF_904WLdckytlkyQpWHcmSxl7E_c84n4b_l2_xo>52966</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`std::uniform_real_distribution` internal calculation overflow
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mordante
</td>
</tr>
</table>
<pre>
Using the following range `[-std::numeric_limits<F>::max(), std::numeric_limits<F>::max())` for `std::uniform_real_distribution<F>` won't work properly and always generates `inf` values.
```
template<class _RealType>
template<class _URNG>
inline
typename uniform_real_distribution<_RealType>::result_type
uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
return (__p.b() - __p.a())
* _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
+ __p.a();
}
```
calculates `std::numeric_limits<F>::max() - -std::numeric_limits<F>::max()` which overflows. [cppreference](https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution) links to this [paper](https://hal.archives-ouvertes.fr/hal-03282794/document) which proposes a fix for #19141. Implementing that solution may also be a solution for this issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVEtzmzAQ_jVw0ZgBYbA5cIjjpNNLD2nSKyNgATVCYiRhx_--KzBOPUk6NSMe0u63--2LUtWn_MVw2RLbAWmUEOrodprJFoiXhl6yWxlbe_EdLjn2oHlVCN5za7z4_tGLH2ZRz948uvVo5tF7ciMgQz_oWzt_F-goOR71hQYmipobq3k5Wq7kYgUxR9zRjcW3fiWDVgNocSJM1oSJIzsZ0oIEzSwYZ5rLxoEOTIxgAuKFey-8Oz8x0HlNWwv9IBCGrirBjCHFE7J4Pg3gHH-h8vL049tFzKXgEs6qiJOsB_KvkK48TAnQYEZhC4ee7dwGd8lgVuklyduZIE1JUbSuSJWSxpKBadbPTibR4JTnnGx28wfBS4MdtSTOTDEE5WyUrBwgYO91vOi7y6N3pPj183k_E1pqUVRMKskrJq54I6MP3fIxqpq3k-hhYtJ-4nN3xSneLcHsP600sqhGsXTITX2L0d84Ga5jO151RB1ANzhprguTXTUMGhrQICvwkj0qd9YOxqHpIy6Qwd8qQaV6PD3ijcf4PPvGL5zaehJ-3SrIGzvz1RCrcOS5cQQGhr3ymeeOiYDpquMHMCs1ImtMVNDoWbQKY7qlm2yN21pVyEJaZ3-O0Y2jMphXRhr-No83jaMsWkcB-Y7DA05__vMwS4wSE0HSM5xgYRQpAaGXY4ef-HJjRgj8Oo_rLM6Yb7kVkP_fnwMLwKUFLZkgS-Wd8aUe_qhFfp0CbLduLM85F-KwvFYY32-oMODHiZHBj4Rmaep3-aYMG9qE67oOt2myxpiTbQMxCuMkowC-YCUIk2PqPUoFL7F2u2lRrILPcxpSGkZhHG3jTZwFdLOO4iat0jRqGE1ibx1Cz7gIHJFA6dbX-cSpHFuDQoExm3ch_p14KwEmf2ifjbZTOu-Vrhlmw5_45xP5P8lc6MA">