--- In gbadev@yahoogroups.com, "Thomas" <sorcererxiii@y...> wrote:
> I'd like a general algorithm in C or psuedocode that could be
> used for different fraction sizes just be changing a #define
> value. I've searched and found some that worked for specific
> cases (like one that was 2.30)
For reference, here's an example of a 2.30 square root function:
http://www.worldserver.com/turk/opensource/FractSqrt.c.txt
> but I could figure out how to adapt it for 22.10.
The given code gives sqrt(1<<30) == 1<<30. You want
sqrt(1<<10) == 1<<10 and sqrt(1<<30) == 1<<20. So use the
2.30 code and just shift the result right by 10 binary places.
In general, if you have n fractional places (in your case 10),
where n is odd and 0 <= n <= 30, then shift right by (30-n)/2
after calling the 2.30 routine.
Division is rather slow on ARM; don't use the division based
Newton's method code that somebody else just posted.
--
Damian