Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Strictfp
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{lowercase title|title=strictfp}} '''strictfp''' is an obsolete and redundant reserved word in the [[Java (programming language)|Java programming language]].<ref>{{Cite web|title=Java Language Specification - Chapter 3. Lexical Structure|url=https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-ReservedKeyword}}</ref><ref name=":0">{{Cite web|title=JEP 306: Restore Always-Strict Floating-Point Semantics|url=https://openjdk.java.net/jeps/306}}</ref> Previously, this keyword was used as a modifier that restricted [[floating-point]] calculations to [[IEEE 754]] semantics to ensure portability. The strictfp keyword was introduced into Java with the [[Java virtual machine]] (JVM) version 1.2 and its functionality was removed in JVM version 17.<ref name=":0"/> As of Java 17, IEEE 754 semantics is required, thus using this keyword has no effect. ==Basis== The [[IEEE]] standard [[IEEE 754]] specifies a standard method for both floating-point calculations and storage of floating-point values in various formats, including single (32-bit, used in Java's <code>float</code>) or double (64-bit, used in Java's <code>double</code>) precision. Some hardware also provides [[extended precision]] formats that provide higher precision and/or a larger exponent range. On such architectures, it may be more efficient to compute intermediate results using such extended formats. This may avoid [[round-off error]]s, [[Arithmetic overflow|overflows]] and [[Arithmetic underflow|underflows]] that would otherwise occur, but can cause programs to produce different output on such architectures. It was particularly expensive to avoid the use of extended precision on x86 machines with the traditional [[x87]] floating-point architecture. Although it was easy to control calculation precision, limiting the exponent range for intermediate results required additional costly instructions. Before JVM 1.2, floating-point calculations were required to be strict; that is, all intermediate floating-point results were required to behave as if represented using IEEE single or double precisions. This made it expensive on common x87-based hardware to ensure that overflows would occur where required. Starting with JVM 1.2, intermediate computations were, by default, allowed to exceed the standard exponent ranges associated with IEEE 32-bit and 64 bit formats. They were permitted to instead be represented as a member of the "extended-exponent" value set. On platforms like x87, overflows and underflows might not occur where expected, producing possibly more meaningful, but less repeatable, results instead. Since x87 floating point is no longer necessary on x86 processors supporting [[SSE2]], Java 17 again made all floating-point operations strict, effectively restoring the pre-1.2 semantics.<ref name=":0"/> == How it works == In the absence of overflow or underflow, there is no difference in results with or without strictfp. If repeatability is essential, the strictfp modifier can be used to ensure that overflow and underflow occur in the same places on all platforms. Without the strictfp modifier, intermediate results may use a larger exponent range.<ref>{{cite book|first1= James|last1= Gosling|first2= Bill |last2= Joy|first3= Guy L. Jr.|last3=Steele|first4=Gilad|last4=Bracha|first5=Alex|last5=Buckley|first6=Daniel|last6=Smith|title=The Java Language Specification, Java SE 9 Edition|url=https://docs.oracle.com/javase/specs/jls/se9/html/jls-4.html#jls-4.2.3|access-date= 2017-10-06|year= 2017|publisher= Addison-Wesley Professional|chapter= 4.2.3 Floating-Point Types, Formats, and Values}}</ref> The <code>strictfp</code> modifier accomplishes this by representing all intermediate values as IEEE single precision and double precision values, as occurred in earlier versions of the JVM.<ref>{{cite book |last=Flanagan |first=David |author-link=David Flanagan |title=Java in a Nutshell |edition=Fifth |publisher=[[O'Reilly Media]] |date=March 2005 |isbn=978-0-596-00773-7 |url=https://archive.org/details/javainnutshell00flan |access-date=2010-03-03 |url-access=registration }}</ref> ==Usage== Programmers can use the modifier <code>strictfp</code> to ensure that calculations are performed as in the earlier versions; that is, only with IEEE single and double precision types used. Using strictfp guarantees that the results of floating-point calculations are identical on all platforms. It can be used on [[Class (computer science)|classes]], [[Interface (computer science)|interfaces]], and non-abstract [[Method (computer science)|methods]].<ref>{{cite book|first=Herbert|last=Schildt|title=Java: A Beginner's Guide|edition=4|publisher=McGraw-Hill Companies|year=2007|isbn=978-0-07-226384-8}}</ref> When applied to a method, it causes all calculations inside the method to use strict floating-point math. When applied to a class, all calculations inside the class use strict floating-point math. Compile-time constant expressions must always use strict floating-point behavior.<ref>{{cite book|first1= James|last1= Gosling|first2= Bill |last2= Joy|first3= Guy L. Jr.|last3=Steele|first4=Gilad|last4=Bracha|title=The Java Language Specification, Third Edition|url=https://docs.oracle.com/javase/specs/jls/se6/html/expressions.html#15.4|access-date= 2016-03-22|year= 2005|publisher= Addison-Wesley Professional|isbn= 0-321-24678-0|page= 411|chapter= 15.4 FP-strict Expressions}}</ref> '''Examples''' <syntaxhighlight lang="java"> public strictfp class MyFPclass { // ... contents of class here ... } </syntaxhighlight> == References == {{Reflist}} [[Category:Java (programming language)]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Lowercase title
(
edit
)
Template:Reflist
(
edit
)