brintos

brintos / llvm-project-archived public Read only

0
0
Text · 992 B · 2c82e6f Raw
40 lines · plain
1.. title:: clang-tidy - bugprone-integer-division2 3bugprone-integer-division4=========================5 6Finds cases where integer division in a floating point context is likely to7cause unintended loss of precision.8 9No reports are made if divisions are part of the following expressions:10 11- operands of operators expecting integral or bool types,12- call expressions of integral or bool types, and13- explicit cast expressions to integral or bool types,14 15as these are interpreted as signs of deliberateness from the programmer.16 17Examples:18 19.. code-block:: c++20 21  float floatFunc(float);22  int intFunc(int);23  double d;24  int i = 42;25 26  // Warn, floating-point values expected.27  d = 32 * 8 / (2 + i);28  d = 8 * floatFunc(1 + 7 / 2);29  d = i / (1 << 4);30 31  // OK, no integer division.32  d = 32 * 8.0 / (2 + i);33  d = 8 * floatFunc(1 + 7.0 / 2);34  d = (double)i / (1 << 4);35 36  // OK, there are signs of deliberateness.37  d = 1 << (i / 2);38  d = 9 + intFunc(6 * i / 32);39  d = (int)(i / 32) - 8;40