brintos

brintos / llvm-project-archived public Read only

0
0
Text · 537 B · 0a5047a Raw
17 lines · plain
1.. title:: clang-tidy - bugprone-incorrect-roundings2 3bugprone-incorrect-roundings4============================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 float15   number below 0.5) rounds to 1.0. Even worse behavior for negative16   numbers where both -0.5f and -1.4f both round to 0.0.17