gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > I need a fast powf function

#47550 - zonked - Sun Jul 10, 2005 7:58 pm

Hi!

In my current project I need a very fast powf function, it is used in a inner loop.

It should look something like this:

f32 powf (f32 a, f32 b)

f32 res = powf (2, .5);

res = 1.4142 ...

And use fixed point.

I hope some one can help me!
_________________
while (!dead)c++;

#47552 - tepples - Sun Jul 10, 2005 8:15 pm

Power of .5 is square root; there are dedicated square root functions that are faster. Will it always be powf(x, .5)?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#47557 - zonked - Sun Jul 10, 2005 10:08 pm

I want the function to work for any numbers.
Could be:

powf (cos(12.125), sin (1.2))

I think you get it :)
_________________
while (!dead)c++;

#47559 - tepples - Sun Jul 10, 2005 10:24 pm

Can you substitute lookup tables?

It may sound like I'm skirting the issue, but skirting the issue is an important part of design-level optimization when a program is intended to run in real time on fixed hardware.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#47569 - DekuTree64 - Sun Jul 10, 2005 11:13 pm

I'd be interested in seeing a fixed-point power function too. I don't have any specific use for it, but I've never seen one before, and I'm sure it would come in handy sometimes.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#47578 - chishm - Mon Jul 11, 2005 12:10 am

The accuracy and speed can vary with this method, but you could use a logarithm and expontential lookup table with a multiply. Take the log of the mantisse or base number (a), multiply it by the exponent (b) then find the exponential power of the result.
That is a^b = e^(ln(a) * b)