Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Java language allows platforms to use available floating-point hardware that can provide floating-point support with exponents that contain more bits than the standard Java primitive type double (in the absence of the strictfp modifier). Consequently, these platforms can represent a superset of the values that can be represented by the standard floating-point types. Floating-point computations on such platforms can produce different results than would be obtained if the floating-point computations were restricted to the standard representations of float and double. According to the Java Language Specification (JLS), §15.4, "FP-strict Expressions",:

Wiki Markup
the net effect \[of non-fp-strict evaluation\], roughly speaking, is that a calculation might produce "the correct answer" in situations where exclusive use of the float value set or double value set might result in overflow or underflow.

...

An expression is strict when any of the containing classes, methods, or interfaces is declared to be strictfp. Constant expressions containing floating-point operations are also evaluated strictly. All compile-time constant expressions are by default , strictfp.

Strict behavior cannot be inherited by a subclass that extends a strictfp superclass. An overriding method can independently choose to be strictfp when the overridden method is not, or vice versa.

Noncompliant Code Example

...

The lost magnitude would also have been lost if the value were stored to memory, ; for example, to a field of type float.

Compliant Solution

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d1ad5c4829294a74-6bfaf245-4005475a-a4d5a6c5-fecf5d4cfb0b2fc132ec5b10"><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="cc355b4be411c6b9-01484ee3-472d4f4e-86e283e3-31abbddb364a7abf1bab73b5"><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="fd96e3b5cf7c0773-61bd1220-42a945e9-8885862f-0e2e90cf4686619969cbf285"><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="7dd33a17e1769696-cb755674-4c6a4e75-bc759f7e-0bd46a638c173710b48211ad"><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>

...