Home java The strictfp modifier

The strictfp modifier




What is this modifier for? And what can you use it with?

Answer 1, authority 100%

strictfp is a modifier introduced in java 1.2 that limits the precision of IEEE floats and doubles. What is it for? To ensure portability. The fact is that the JVM uses all possible processor precision, and it is different on different systems, so the result may be different. This modifier is used in programs that require computational precision exceeding IEEE (usually something related to science).

strictfp class StrictFPClass {
  double num1 = 10e + 102;
  double num2 = 6e + 08;
  double calculate () {
    return num1 + num2;

strictfp interface StrictFPInterface {
  double calculate ();
  strictfp double compute (); // compile error

class StrictFPMethod {
  strictfp double computeTotal (double x, double y) {
    return x + y;

In a class, it means that all methods on all systems will return real numbers with the same precision.
0.112 and 0.113
If these numbers are compared with accuracy to hundredths, then they will be the same. An example of how precision affects calculations.
You can not use it because almost all modern compilers already substitute it for us (I read this somewhere in the manual)

Answer 2, authority 59%

The strictfp modifier is applied to classes, interfaces, and methods to ensure that all floating point operations comply with the IEEE 754 standard.

When using this modifier, you will get the same behavior when manipulating floating point numbers on all platforms.

You can also read about FP-strict in JLS .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions