What is it for and where should I use "strictfp"

Asked

Viewed 128 times

2

I was reading the Java 9 specification and came across the keyword strictfp, What good is only that it is not clear.

What good is that and where I should apply it?

Why is it not so used in the programs today?

Because it has not been removed (if not used)?

  • I had seen this answer but did not clarify all my doubts. I edited the question.

  • Related: https://answall.com/q/455/64969 I removed my closing vote due to the edition, which made it clear that another point was

1 answer

2


There is a technical standard called IEEE 754, which defines how the double precision is to be represented in practice in floating point. In Java, this representation is materialized in the data type double. In other words, the representation of this technical standard is followed to the letter when working with double in Java.

When and when the JVM controls and performs operations involving double, there is a guarantee that double precision occurs the way it should occur (follows IEEE 754). However, for reasons of optimization and speed, it can happen that the JVM delegate these operations to the processor of the machine and that is where things can get complicated because, as we know, there are several types of processor in the market, each with its specific architecture and characteristics, including how they deal with calculations involving floating points and that do not necessarily follow the aforementioned technical standard. This means that there is no guarantee that the same calculation, involving the same numbers, will always generate the same accuracy on different processors (i.e., the result is not deterministic) and this can be a problem if you, for example, it has a mathematical application program that requires extreme precision.

To ensure that a calculation with these numbers is always performed by the JVM and not delegated to the processor (then eliminating the possibility of different results depending on the processor), the keyword is used in the variables that will be used in this calculation strictfp. This ensures that regardless of the platform on which your program runs, a floating point calculation will be deterministic (given the same input data, the result will always be the same).

For 99.9% of developers, however, these eventual differences don’t matter, since most of the applications they develop don’t require such accuracy, and this explains why you can hardly see this keyword being used, but make no mistake, it is used yes, probably in scientific applications, such as particle accelerators or even mathematical modeling.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.