| Issue |
52966
|
| Summary |
`std::uniform_real_distribution` internal calculation overflow
|
| Labels |
libc++
|
| Assignees |
|
| Reporter |
mordante
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs