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.

C/C++ > Fixed-Point Powers and Exponents

#58889 - strager - Wed Oct 26, 2005 11:57 pm

Does anybody know how to handle powers/exponents with fixed numbers?
Here's the actual situation: I have two fixed numbers, both 16.16, and I need to raise one to the other; as in such:
a ^ (1 / 2.4)
a is some random number calculated by the parameters to the function and other factors. I need to know how to calculate that in C... because using floats is slow 'n' stuffs...

Thanks!

#58898 - tepples - Thu Oct 27, 2005 12:38 am

What will you use this value for? If it's for gamma correction, then use a lookup table.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#58901 - strager - Thu Oct 27, 2005 1:12 am

tepples wrote:
What will you use this value for? If it's for gamma correction, then use a lookup table.

Basically, but how am I going to use a lookup table for all possible 4 billion values? Maybe I could leave only the 8 most accurate bits and do a LUT on that? Or what would you recommend I do?

Thanks...

#58903 - tepples - Thu Oct 27, 2005 1:31 am

strager wrote:
but how am I going to use a lookup table for all possible 4 billion values? Maybe I could leave only the 8 most accurate bits and do a LUT on that?

Remember that all you need is a 5-bit output per channel. Use enough of a lookup table that gives you accuracy down to 5 bits.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#58915 - SevenString - Thu Oct 27, 2005 5:44 am

As a shortcut, sometimes linear interpolation between lookup table values can provide reasonable results, even if the lookup table is non-linear.
_________________
"Artificial Intelligence is no match for natural stupidity."

#58965 - legalize - Thu Oct 27, 2005 5:50 pm

Have you tried looking at the sources to a free math library, like oslib on sourceforge?