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

3

I'm not aware of this keyword, I've never seen an example code used. Until I discovered her existence today when reading some books on Java, however it was not clear what the utility. What is strictfp ? What is it for? When to use?

    
asked by anonymous 29.12.2014 / 22:14

2 answers

5

It's to try to ensure compatibility between architectures.

Non-strict FP mode is designed to give greater accuracy in calculations on architectures with floating point implementations with greater precision than Java uses. This is the Java standard.

But this has brought compatibility issues of calculated values depending on where the execution is done.

Source: Wikipedia .

So 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 precision. It has just enough accuracy. So it changes little in most cases.

This is where the phrase "Write-Once-Get-Equally-Wrong-Results-Everywhere" is born.

Source: OS response .

    
29.12.2014 / 22:37
4

The stricfp is used to create the extended precision call. This extended precision was created due to the need for some programmers to require more precise computation over floating-point values. EX: Given the following statement:

double result = val1 * val2 / val3; 

What happened was that many Intel processors computed val1 * val2 and left the result in an 80-bit register and only after partitioning by val3, they truncated back to 64 bits. This situation resulted in a more accurate and less prone to overflow of exponents, but the result was different from the computations that used 64 bits all the time.

What happened was that the Java Virtual Machine specification required that all intermediate computations be truncated, that is, even if the processor could perform the intermediate computation by writing the result to an 80-bit register, the JVM caused all intermediate operations were truncated, which caused discontent in the JAVA community, as it made the operation slower (computing with truncation takes longer than more precise computations) and made it more prone to overflowing exponents.

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

source: link

    
30.12.2014 / 14:27