java is not common keywords: strictfp

1.strictfp, namely strict float point (precision floating point).
  strictfp keyword can be applied to classes, interfaces or methods. When using strictfp keyword to declare a method that all float and double expressions are strictly abide by the FP-strict restrictions, in line with IEEE-754 specifications. When using a keyword strictfp class or interface, all such codes, including codes and initial setting value of the nested type, will be calculated strictly. Strictly bound by the results of all means of expression must be IEEE 754 arithmetic, logarithmic operation is expected to result in a single-precision and double-precision format.
  If you want your floating-point arithmetic is more accurate, but not because of inconsistent results from different hardware platforms performed, you can use the keyword strictfp.

Examples are as follows:

Examples strictfp do not use:

 1 public class TestNoStrictfp {
 2     private static double aDouble = 0.0555500333333212d;
 3     private static float aFloat = 0333000000222f;
 4     
 5     public static void main(String[] args) {
 6         
 7         double cDouble = aDouble / aFloat;
 8         
 9         System.out.println("aDouble:" + aDouble);
10         System.out.println("aFloat:" + aFloat);
11         System.out.println("cDouble:" + cDouble);
12     }
13 
14 }
Examples of use strictfp:
 1 public strictfp class TestStrictfp {
 2     private static double aDouble = 0.0555500333333212d;
 3     private static float aFloat = 0.0333000000222f;
 4     
 5     public static void main(String[] args) {
 6         
 7         double cDouble = aDouble / aFloat;
 8         
 9         System.out.println("aDouble:" + aDouble);
10         System.out.println("aFloat:" + aFloat);
11         System.out.println("cDouble:" + cDouble);
12     }
13 
14 }

operation result:

Examples of not using strictfp operating results:

aDouble:0.0555500333333212
aFloat:3.33000016E11
cDouble:1.6681690896577544E-13

Use examples strictfp operating results:

aDouble:0.0555500333333212
aFloat:0.0333
cDouble:1.668169110346482

Guess you like

Origin www.cnblogs.com/zhuitian/p/11441867.html