...
Note that this compliant solution also specifies that the floating-point literals (1.1
) are of type double
to clarify their expected type; this complies with guideline rule "NUM18-J. Be aware of numeric promotion behavior."
...
Code Block | ||
---|---|---|
| ||
strictfp class Example { double d = 0.0; public void example() { float f = Float.MAX_VALUE; float g = Float.MAX_VALUE; this.d = f * g; System.out.println("d (" + this.d + ") might not be equal to " + (f * g)); } public static void main(String[] args) { Example ex = new Example(); ex.example(); } } |
Exceptions
NUM09-EX1: This guideline rule applies only to calculations that require consistent floating-point results on all platforms. Applications that lack this requirement need not comply.
...
Sound automated detection of violations of this guideline rule is not feasible in the general case.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="09f0c046b5387e70-967d2511-47604aa8-ac71b8bb-2a747d17a091c4d6e5a27b95"><ac:plain-text-body><![CDATA[ | [[Darwin 2004 | AA. Bibliography#Darwin 04]] | Ensuring the Accuracy of Floating-Point Numbers | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="098d0ce5ea343f5c-27183c99-488349ee-aea09f97-3314dd084e81811dd5a2b724"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§15.4, "FP-strict Expressions" | http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.4] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6da7568c8f2877ae-3be04b0b-43ea4a9d-96d0b223-639838c11a77fda931035ff2"><ac:plain-text-body><![CDATA[ | [[JPL 2006 | AA. Bibliography#JPL 06]] | 9.1.3. Strict and Non-Strict Floating-Point Arithmetic | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ad8c0c65776b5be7-bab9d7bb-4067406b-b76ca680-7c8ab191e6e450d07b3b6e43"><ac:plain-text-body><![CDATA[ | [[McCluskey 2001 | AA. Bibliography#McCluskey 01]] | Making Deep Copies of Objects, Using strictfp, and Optimizing String Performance | ]]></ac:plain-text-body></ac:structured-macro> |
...