...
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 | ||||
|---|---|---|---|---|
| ||||
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 | ||||||
| 442 S | Fully implemented. | |||||||
| PRQA QA-C |
| 4117 | Partially implemented. | ||||||
Splint |
|
|
|
...