...
The output produced is 2.0E9 whereas, the expected output is 1.999999999E9.
Compliant
...
Solution
In this case, a double should be used instead of a float for a safe widening primitive conversion caused by integer promotion.
...
| Code Block | ||
|---|---|---|
| ||
int result = 0; for(int i = 0; i < 4; i++) result = ((result << 8) | b[i]); |
Compliant Solution
This compliant solution does not avoid integer promotion but works around it by masking off the upper 24 bits of the byte array element.
...