«« Next » « Previous
«« Next » « Previous

Link Details

Link 46120 thumbnail
User 202203 avatar

By sunitram
via martin.ankerl.com
Published: Oct 05 2007 / 06:02

This is a tricky approximation to the a^b calculation. On the tested machine the Java version is 27 times faster than Math.pow(), in C++ it is 7.8 times faster. This is just an approximation, but it might be good enough for many use cases.
  • 11
  • 3
  • 2548
  • 682

Comments

Add your comment
User 202203 avatar

sunitram replied ago:

0 votes Vote down Vote up Reply

This is it. I am pretty sure that are the 3 lines of code that took me longest to develop in all the code I have written. It is also the most obscure, and the most amazing code :-)

User 202203 avatar

sunitram replied ago:

0 votes Vote down Vote up Reply

Another benchmark: on a Pentium 4, Windows, Java 1.6.0 -server, the approximation is 41 times faster than Math.pow()

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.