Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast Integer Square Roots
#3
Go right ahead! The source code is listed in the library. http://www.boriel.com/wiki/en/index.php/...IC:Library

Note that for square roots, there are two options - an accurate one, about 6 times faster than the ROM version (which ironically, still uses the ROM's FP calculator. It's just a better algorithm by far than the horrid kludge built into the ROM - though admittedly, them doing it in 7 bytes was a neat trick). This should always give the same result as the ROM routine. You might consider the bytes it costs reasonable for general use (would it be better to default to this, and have a --small option instead? It does make the compiler look more impressive Smile ) I think I just hand counted it at 45 bytes. That's not a huge cost for X6 speed up of a function.

The integer one is about 100 times faster than the ROM routine for 16 bit numbers, and 50 times faster for 32 bit numbers. It gives an integer result, not a full floating point one. Have a play with them, and see what you think. I think I would recommend leaving the integer one as a #include option. It behaves differently, though it does go like greased lightning!

For those demos, I used the integer version; which is fine for most quick and dirty games calculations.

Play with them, and you should see how they work.

You might want to adjust the source for fsqrt.bas so that it reports an error for negative numbers, though, if you are considering it as a default. Right now it cheats and makes all numbers positive.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)