Search code examples
javamathfloating-pointstrictfp

Doubt about strictfp and StrictMath


I have a little technical question, is it the same to call:

   public static strictfp double myMethod(double phi){
       return Math.exp(phi);
   }

or:

   public static double myMethod(double phi){
       return StrictMath.exp(phi);
   }

Or does the strictfp keyword just applies to the basic arithmetic operations + - * / used inside the method?


Solution

  • Or does the strictfp keyword just applies to the basic arithmetic operations + - * / used inside the method?

    The strictfp keyword only applies to operations in the method or class it modifies. It doesn't reroute calls to Math functions to StrictMath, so you need to explicitly use StrictMath instead of Math.

    From http://www.esus.com/javaindex/j2se/jdk1.2/javamath/strictfp.html

    If a floating point expression is within a strictfp "scope", the results will be as predictable as described in IEEE 754 ...