What is and what is the reserved word "strictfp" for?

Asked

Viewed 1,659 times

4

I don’t know this keyword, I’ve never seen an example of code in which it was used. Until today I discovered her existence by reading some books about Java, however it was not clear what the utility is. What is strictfp? What is it for? When to use?

2 answers

7


It’s to try to ensure compatibility between architectures.

The way non Strict FP was created to give greater precision in calculations on architectures with floating point implementations with greater precision than Java uses. This is the Java standard.

But this has caused compatibility problems of calculated values depending on where the execution is done.

Source: Wikipedia.

Then you should use it whenever you know you need the same results no matter where you are running the application.

Almost always this is not necessary after all binary floating point types no longer have absolute accuracy. It has just enough accuracy. So it changes little in most cases.

Hence the expression "Write-Once-Get-Equally-Wrong-Results-Everywhere".

Source: response from the OS.

  • Suggested response improvement: strictfp can diminish the accuracy and speed of execution, its advantage is to be predictable, running the same on any processor, be it x86, ARM, SPARC, etc.

  • @thanks for the remark but the problem was another. I was talking about the default current Java to show why it was necessary to create the strictfp.

  • Yes, I saw your edition (adding "non") and now I understood that the intention was to explain how it works without strictfp.

4

The stricfp is used to create the so-called extended accuracy. This extended accuracy was created due to the need for some programmers to need more precise computation over floating point values. EX: Given the following instruction:

double result = val1 * val2 / val3; 

What happened was this: many Intel processors computed val1 * val2 and left the result in an 80bit register and only after dividing by val3 did they truncate back to 64bit. This situation generated a more accurate result and less prone to bursting of exponents, but the result was different from the computations that used 64bits all the time.

What happened was, the specification of the Java Virtual Machine required all intermediate computations to be truncated, that is, even if the processor could perform intermediate computation by recording the result in an 80bit register, the JVM caused all intermediary operations to be truncated, which caused discontent in the JAVA community as it slowed down the operation (truncated computing takes longer than more accurate computations) and made it more prone to exponent bursts.

The creation of strictfp was precisely to address this issue of performance optimization and also the question of accuracy of results. Now, in case the user needs greater accuracy in their result and better performance, he can use strictfp.

source: http://javafree.uol.com.br/topic-863961-Uso-do-strictfp.html

Browser other questions tagged

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