Wanted to play with std::nan and std::nanf to create nan values with some custom payload (non boxing).
However, it really does not work as expected:
Firsty, with Visual Studio 2015, the function apparently is not impelemnted right. The exact sample proposed by cppreference.com produces:
nan("1") = nan (7ff8000000000000)
nan("2") = nan (7ff8000000000000)
Which is not what we expect. Is VS implementation wrong?
Secondly, why does the standard define std::nan (the one returning double) in such a way that is has a flaw when value is later being casted to a float? I mean that it would have been smarter to have std::nan("1") produce 0111111111111000000000000000000000100000000000000000000000000000 rather than 0111111111111000000000000000000000000000000000000000000000000001 so that we would have std::nan("1") == std::nanf("1")! Then the "custom nan" value is preserved when casted from float to double and the way around.
Aucun commentaire:
Enregistrer un commentaire