...
This compliant solution uses an integer loop counter from which the floating-point value is derived. Additionally, it uses a double
to ensure that the available precision suffices to represent the desired values. The solution also runs in FP-strict mode to guarantee portability of its results. See NUM06 NUM53-J. Use the strictfp modifier for floating-point calculation consistency across platforms for more information.
Code Block | ||
---|---|---|
| ||
for (int count = 1; count <= 10; count += 1) { double x = 100000000.0 + count; /* ... */ } |
...
Automated detection of floating-point loop counters is straightforward.
Related Guidelines
FLP30-C. Do not use floating-point variables as loop counters | VOID FLP30-CPP. Do not use floating point variables as loop counters | ||
Floating-point Arithmetic [PLF] |
...