Как вы std::round удваиваете число, но округляете его до нуля в промежуточных случаях? ⇐ C++
-
Anonymous
Как вы std::round удваиваете число, но округляете его до нуля в промежуточных случаях?
I am in a situation where I need to round 0.5 and -0.5 down to 0. So I checked various documentations -
The generic C++ methods seems always round 0.5 away from 0.
https://en.cppreference.com/w/cpp/numeric/math/round
While if I go the lower level way by setting rounding style, it seems a very global approach and could potentially have threading and CPU state implication which is quite annoying.
https://en.cppreference.com/w/cpp/types ... ound_style
Is there a light-weight, standard library and simple way to achieve rounding down to 0?
Источник: https://stackoverflow.com/questions/780 ... fway-cases
I am in a situation where I need to round 0.5 and -0.5 down to 0. So I checked various documentations -
The generic C++ methods seems always round 0.5 away from 0.
https://en.cppreference.com/w/cpp/numeric/math/round
While if I go the lower level way by setting rounding style, it seems a very global approach and could potentially have threading and CPU state implication which is quite annoying.
https://en.cppreference.com/w/cpp/types ... ound_style
Is there a light-weight, standard library and simple way to achieve rounding down to 0?
Источник: https://stackoverflow.com/questions/780 ... fway-cases
Мобильная версия