Any optimisations on Math.log() and Math.exp() ?

Hi,

I’m writing a program which will need to call Math.log() and Math.exp() quite a bit, and knowing that these are pretty intensive functions, was wondering if anyone has written any accurate faster math optimisations of them ?

Also Math.sqrt(), I’m aware of some bitwise operation routines which are faster on some JVMs, but it seems more recent JVMs are pretty well optimised in Math.sqrt() already ?

Cheers

Write it in C, using SSE2.

If you’re really looking for performance, it makes no sense to work with the JVM that doesn’t support SIMD.

http://gruntthepeon.free.fr/ssemath/

yuk.

Could I use JNI into that C module, or is that just silly ?

Yes, use JNI, but you have to work with fairly large datasets per call, preferably in a native FloatBuffer or DoubleBuffer

Tons of options here. More info is needed, such as any range limitations, precision requirements
and what your using them for.

Depending on usage a pure Java approximation method could be faster than going to native, assuming
that no significant batching is possible. But even if going to native, knowledge of how the functions are
to be used is important in these kind of questions.

Hi there, thanks for the response.

Actually so far in the build, the speed of the programme is holding up very well, there’s plenty of time left in each cycle, so I don’t think calling the Math functions is causing me any performance problems. I’ll leave them in for now, for the accuracy they give.

Of course I might come back if they do start to be too intensive down the road.

Cheers