samedi 24 décembre 2016

Adding smallest possible float to a float

I want to add the smallest possible value of a float to a float. So, for example, I tried doing this to get 1.0 + the smallest possible float:

float result = 1.0f + std::numeric_limits<float>::min();

But after doing that, I get the following results:

(result > 1.0f) == false
(result == 1.0f) == true

I'm using Visual Studio 2015. Why does this happen? What can I do to get around it?

Aucun commentaire:

Enregistrer un commentaire