Wednesday, 18 June 2014

strictfp

The strictfp keyword is used to force the precision of floating point calculations (float or double) in Java conform to IEEE’s 754 standard, explicitly. Without using strictfp keyword, the floating point precision depends on target platform’s hardware.

In simple terms strictfp ensures that you get exactly the same results from your floating point calculations on every platform. If you don't use strictfp, the JVM implementation is free to use extra precision where available.

If an interface or class is declared with strictfp, then all methods and nested types within that interface or class are implicitly strictfp.

strictfp class SampleFloat{ 
 static double mul(double a){
  return (2 * a * 0.5);
 }

 public static void main(String args[]){
  double var1 = 8e+307;
  System.out.println("Multiplication = " + mul(var1));
 }
}


                                                             Home

No comments:

Post a Comment