isocpp / isocpp/CppCoreGuidelines
Explicitly specify float to int conversions
Open
@neilmacintosh is already working on this.
Since Oct 11, 2018.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
Always explicitly specify how the conversion from float to integer should be done. That is, always specify one of floor, ceil, trunc, round, rint, or nearbyint. Or one of the long or long long variants, lround, llround, etc.
static_cast<int>(double) does the equivalent of static_cast<int>std::trunc(double), but that is not always the best choice. Often floor, or one of the round variants, is preferable. Explicitly specifying encourages us to make a thoughtful choice. If std::trunc is what you want, say that explicitly, too.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.