Thanks, I'll try that out . . . for some reason my brain is not
working on this issue (years of only having to press the square root
key on a calculator?). I also figured out that I can use the bios
square root (I think) by realizing that
sqrt(n * 1024) = sqrt(n)*sqrt(1024) = sqrt(n) << 5.
I'll need to compare to see which method is faster/more accurate.
Tom
--- In gbadev@yahoogroups.com, "Damian Yerrick" <d_yerrick@h...>
wrote:
> --- 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