...
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-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; /* ... */ } |
...
FLP30-C. Do not use floating point variables as loop counters | ||||
FLP30-CPP. Do not use floating point variables as loop counters | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="aff23c5387a26637-c20d558a-4f844258-9f6ba8b4-bc78d791657eccd3fdc08b4b"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | Floating-point Arithmetic [PLF] | ]]></ac:plain-text-body></ac:structured-macro> |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="85e02ee2336d96c1-39c4ce04-4e7a4cf9-9fd1b34f-2bacb4f8724db61394e8e422"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. References#Bloch 05]] | Puzzle 34. Down for the count | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d7554cbbc32909c9-227bd76a-475e40d7-bd8d9257-475237dd61342923e4e3247c"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. References#JLS 05]] | [§4.2.3, Floating-Point Types, Formats, and Values | http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3] | ]]></ac:plain-text-body></ac:structured-macro> |
...