...
This compliant solution also specifies that the floating-point literals (1.1
) are of type double
to clarify their expected type and minimize maximize their lack of precision.
Noncompliant Code Example
...
This compliant solution uses the strictfp
keyword to require exact conformance with standard Java floating-point. Consequently, the intermediate value of both computations of f * g
will be is identical to the value stored in this.d
, even on platforms that support extended range exponents.
...
NUM06-EX1: The strictfp
modifier may be omitted when competent numerical analysis demonstrates that the computed values will meet all accuracy and behavioral requirements that are appropriate to the application. Note that "competent numerical analysis" generally requires a specialized professional numerical analyst; lesser levels of rigor fail to qualify for this exception.
Risk Assessment
Failure to use the strictfp
modifier can result in implementation-defined behavior with respect to the behavior of floating-point operations.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="77e45e5842d975e7-a0ebafd2-42204a85-a2608792-3f0d4db0a4524bdc0ee521b4"><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="556c4900ecb458cc-3992bebc-4cdc4825-9a7fb666-c27cc1b9b5d41d8af8e67375"><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="c6bdb31563e6b25f-cd2dd430-4f4445c9-a616bf91-982e3c47ea25e81d3b67fe42"><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="b251959147fe3c68-f8d0169e-43ff4a54-9b79b4e3-d532ba7b4845b89f8939086f"><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> |
...