which FP Math library do you use and recommend?

Hello,

I have found http://www.dclausen.net/projects/microfloat/

Do you have any other?

I need to be 100% certain that two hosts compute the exact same value. using the ACOS function and COS function.

Cheers.

The StrictMath versions “should” produce bit identical results on all platforms. The real trick is that you also have to insure that the inputs are the same on all machines. Bit-exact floating point is a nasty can of worms.

java.lang.Math uses java.lang.StrictMath :wink:

If you don’t want super high accuracy, just portability, then use strictfp in your class definition:

Only by default. The JVM patches out the calls to hardware when available. Using strictfp and StrictMath should insure bit portability, but my confidence level of the JVM and compiler being bug-free in all versions isn’t high.

My understanding is that strict fp means as per IEEE definitions and per the Math javadoc, which IIRC just means 2ulp or better (units in last position) for higher functions. That is the last bit or so can be different for things like cos/sin/log/pow/exp etc on different machines/jvm’s and still be complaint.

When i need perfect bit accuracy i use Fixed point (ie ints/longs with a POT divisor) or just plan ints.

With strictfp: loads, stores, add, sub, mul & div are all required to be IEEE compliant…so a given code sequence of these are required to be bit-exact for all archs. StrictMath is required to be bit-exact (to some version of fdlibm). So in combo, you should get bit exact results (again assuming no JVM bugs or compiler bugs). Not that I’d suggest doing this. Assuming that your computation chains aren’t crazy you could just perform the calcualtions in doubles and convert to floats for values that need to be identical.