Questions tagged [strictfp]

`strictfp` is a keyword in the Java programming language that restricts floating-point calculations to ensure portability. It was introduced into Java with JVM version 1.2

strictfp is a keyword in the programming language that restricts floating-point calculations to ensure portability. It was introduced into Java with JVM version 1.2. Prior to JVM 1.2, floating-point calculations were strict; that is, all intermediate floating-point results were represented as IEEE single or double precisions only. As a consequence, errors of calculation (round-off errors), overflows and underflows, would occur with greater frequency than in architectures which did intermediate calculations in greater precision. Since JVM 1.2, intermediate computations are not limited to the standard 32- and 64-bit precisions. On platforms that can handle other representations, e.g. 80-bit double extended on x86 or x86-64 platforms, those representations can be used, helping to prevent round-off errors and overflows, thereby increasing precision. For some applications, a programmer might need every platform to have precisely the same floating-point behavior, even on platforms that could handle greater precision. The strictfp modifier accomplishes this by truncating all intermediate values to IEEE single- and double-precision, as occurred in earlier versions of the JVM.

29 questions
3
votes
0 answers

Scala strictfp annotation causes ClassFormatError

I'm writing a multiplayer game in Scala where the floating-point computations have to happen in exactly the same way on every computer, so I tried adding the @strictfp annotation to every class, object, and trait. However, when I try to run the code…
2
votes
1 answer

Java class declared with strictfp modifier fails test with Modifier.isStrict(int)

To be clear, this question is strictly hypothetical. Personally, I have no Real World need for this behaviour; I discovered it accidentally. Inspired by: How to make a (static) initializer block strictfp? If I declare a Java class with strictfp…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
2
votes
1 answer

Why does the Oracle JDK Javadoc not include the strict floating point modifier?

If I look at the StrictMath.toRadians() in the NetBeans Javadoc window, the top two lines read java.​lang.​StrictMath public static strictfp double toRadians(double angdeg) That makes sense, since the JDK I'm using has StrictMath.toRadians()…
Alonso del Arte
  • 1,005
  • 1
  • 8
  • 19
1
vote
1 answer

Unit of least precision without strictfp

Looking at Math class, the ulp method: public static float ulp(float f) If the method is applied like: Math.ulp(Float.MAX_VALUE), then this rule from the Javadoc documentation comes up: If the argument is ±Float.MAX_VALUE, then the result is equal…
1
vote
2 answers

strictpf in Android from Java Compiler

I have a physics application I want to mantain the deterministic across platforms with scrictfp (which I use and works nowadays in Windows/Mac/Linux Machines) with J2SE 6. I need to convert this code to compile on: -Android -IOS Is this strictfp…
felipe
  • 1,212
  • 1
  • 15
  • 27
1
vote
1 answer

Why strictfp came into existence?

I have always read strictfp restricts floating point calculations to IEEE-754 standard, but never read why their came the need for restricting the calculation's result according to this standard?
Ujjwal
  • 2,365
  • 2
  • 11
  • 7
1
vote
2 answers

Strictfp returns different results on different systems

I'm using the following method on Windows 8 (Intel Atom Z3775): public static strictfp void main(String args[]) { float a = 0.000000002f; float b = 90000300000000004f; float c = a * b; System.out.println(c); } which gives me: …
Geosearchef
  • 600
  • 1
  • 5
  • 22
1
vote
3 answers

How to use strictfp keyword in methods?

I know that the strictfp keyword can be applied on methods, classes and interfaces. strictfp class A{} //Accept strictfp interface M{} //Accept class B{ strictfp A(){} // Not Accept }
Shakthi Vel
  • 61
  • 1
  • 6
0
votes
0 answers

what replaced strictfp in java?

The strictfp keyword was introduced into Java with the Java virtual machine version 1.2 and its functionality was removed in JVM version 17. As of Java 17, IEEE 754 semantics is required, thus using this keyword has no effect. But how to achieve…
felipe
  • 1,212
  • 1
  • 15
  • 27
0
votes
0 answers

Is it possible to get different results if I use strictfp using docker installed on different OS?

I use some double math operations without strictfp in my code. I run docker on different OS but everywhere I use the same dockerFile. Is it posssible to get different results in my math operations? P.S. I know that Strictfp ensures that you get…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
0
votes
1 answer

Should I use `strictfp` modifier when converting `float` to `double`?

If I want to write method converting from float to double. Is there any case the two would give back different result? Which version should I use if I don't care about platform consistency? What if I need it to behave consistently in different…
djy
  • 737
  • 6
  • 14
-1
votes
2 answers

How can we use the strictfp method in a real life pogram?

This question is not a duplicate of this question. I know that the strictfp keyword in java is used for this purpose. But How can we use this in a real life application. What are its advantages?
Arsh Coder
  • 688
  • 9
  • 33
-1
votes
1 answer

Is the access level of strictfp class same as that of default class?

I have below 2 classes in different packages: package chapter1.one; strictfp class SuperClass { protected void testMe() { System.out.println("Testing myself!"); } } package chapter1.two; import chapter1.one.*; public class…
Touhid K.
  • 351
  • 1
  • 5
  • 23
-1
votes
3 answers

what is the use of strictfp non- access modifier?

I know this is a duplicate question. but i want know it with an example. so can anyone explain it with an example? Link to duplicate post: When should I use the "strictfp" keyword in java?
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
1
2