mercredi 10 juin 2015

From the C++11 header , I was wondering if a std::uniform_real_distribution<double> object can spit out a double that's greater than 0.99999999999999994? If so, multiplying this value by 2 would equal 2.

Example:

std::default_random_engine engine;
std::uniform_real_distribution<double> dist(0,1);

double num = dist(engine);

if (num > 0.99999999999999994) 
    num = 0.99999999999999994;

std::cout << 0.99999999999999994 * 2 << std::endl; // 1
std::cout << 0.99999999999999995 * 2 << std::endl; // 2




Aucun commentaire:

Enregistrer un commentaire