1.. title:: clang-tidy - bugprone-incorrect-roundings
2
3bugprone-incorrect-roundings
4============================
5
6Checks the usage of patterns known to produce incorrect rounding.
7Programmers often use::
8
9   (int)(double_expression + 0.5)
10
11to round the double expression to an integer. The problem with this:
12
131. It is unnecessarily slow.
142. It is incorrect. The number 0.499999975 (smallest representable float
15   number below 0.5) rounds to 1.0. Even worse behavior for negative
16   numbers where both -0.5f and -1.4f both round to 0.0.
17