What is the strictfp modifier for? When would I consider using it?

John Mitchell

The strictfp keyword may be applied to both classes and methods. For classes (and interfaces), it specifies that all of the expressions in all of the methods of the class are FP-strict. For methods, it specifies that all of the expressions in that method are FP-strict.

So, what the heck does FP-strict really mean? Well, that actually gets pretty hairy. For the full, gory details check out section 2.18 of Lindholm and Yellin's The Java Virtual Machine Specification Second Edition. If you do not specify strictfp then the compiler & runtime system may be more aggressive in how they deal with floating-point expressions. Whereas with strictfp specified, the compiler and runtime system must toe the line very precisely according to the IEEE-754 floating-point specification.

Basically, what it all boils down to is whether or not you care that the results of floating-point expressions in your code are fast or predictable. For example, if you need the answers that your code comes up with which uses floating-point values to be consistent across multiple platforms then use strictfp.

About | Sitemap | Contact