mardi 15 mars 2016

Why is uniform_int_distribution closed range but uniform_real_distribution is half-open range?

uniform_int_distribution has the interval [a, b] but uniform_real_distribution has the interval [a, b). A naive approach is to do something like b + 0.1, but then you start to get into infinitesimals...luckily the correct approach is simple:

std::uniform_real_distribution<> dis(start, std::nextafter(stop, DBL_MAX));

But why is this necessary? More specifically, what's the rationale that these two are different?




Aucun commentaire:

Enregistrer un commentaire