Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this compliant solution, the decimal error in initialization is eliminated by ensuring that at least one of the operands to the division operation is floating point.:

Code Block
bgColor#CCCCFF
langc
short a = 533;
int b = 6789;
long c = 466438237;

float d = a / 7.0f; /* d is 76.14286 */
double e = b / 30.; /* e is 226.3 */
double f = (double)c * 789; /* f is 368019768993.0 */

...

In this compliant solution, the decimal error in initialization is eliminated by first storing the integer in the floating-point variable and then performing the arithmetic operation. This practice ensures that at least one of the operands is a floating-point number and that the subsequent arithmetic operation is performed on floating-point operands.

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this rule. Any assignment operation where the type of the assigned-to value is float or double, but all the expressions to the right of the assignment are integral, is a violation of this rule.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

442 S
443 S
444 S

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V

4117
4118
4119

Partially implemented.

Splint

Include Page
Splint_V
Splint_V

 

 

...