mercredi 26 septembre 2018

Why does std::uniform_real_distribution

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::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?

Aucun commentaire:

Enregistrer un commentaire