Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  which FP Math library do you use and recommend?  (Read 1939 times)
0 Members and 2 Guests are viewing this topic.
Offline Mordan

Jr. Member
**

Posts: 53



« on: 2011-06-16 09:42:59 »

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.
Offline Roquen

JGO Strike Force
***

Posts: 827
Medals: 25



« Reply #1 on: 2011-06-16 10:07:49 »

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.
Offline ra4king

JGO Kernel
*****

Posts: 3160
Medals: 196


I'm the King!


« Reply #2 on: 2011-06-16 21:21:14 »

java.lang.Math uses java.lang.StrictMath Wink

Games published by our own members! Go get 'em!
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #3 on: 2011-06-17 00:33:23 »

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

http://en.wikipedia.org/wiki/Strictfp

Offline Roquen

JGO Strike Force
***

Posts: 827
Medals: 25



« Reply #4 on: 2011-06-17 01:26:07 »

java.lang.Math uses java.lang.StrictMath Wink

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.
Offline delt0r

Sr. Member
**

Posts: 412
Medals: 12


Computers can do that?


« Reply #5 on: 2011-06-21 10:16:52 »

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.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline Roquen

JGO Strike Force
***

Posts: 827
Medals: 25



« Reply #6 on: 2011-06-27 07:35:24 »

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.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.095 seconds with 17 queries.