5

I want to generate random numbers in the whole double range. Doing it like

std::uniform_real_distribution<double> doubleDist(std::numeric_limits<double>::lowest(),
                                                  std::numeric_limits<double>::max());

produces IND / NaN, though. It took me a while to understand that this is according to documentation:

Requires that a ≤ b and b-a ≤ std::numeric_limits<RealType>::max()

Clearly std::numeric_limits<double>::max() - std::numeric_limits<double>::lowest() is larger than ::max, since :lowest is negative (unlike ::min).

Why can't I generate numbers between lowest and max this way and what is the rationale behind?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
PhilLab
  • 4,777
  • 1
  • 25
  • 77

0 Answers0