Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Fixed Point Square Root   Message List  
Reply | Forward Message #14656 of 15019 |
Re: Fixed Point Square Root

--- 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





Tue Dec 9, 2003 2:25 am

yerricde
Offline Offline
Send Email Send Email

Forward
Message #14656 of 15019 |
Expand Messages Author Sort by Date

Can someone give me a good fixed point square root algorithm? I need to get the square root of a 22.10 fixed point number. I am brain dead when it comes to...
Thomas
SorcererXIII
Offline Send Email
Dec 8, 2003
10:36 pm

input: a = number to be squared x = estimated result (can be any numberm but the better estimation the better result) output: x = close to sqrt(a) algorithm:...
porneL
pornelkurna
Offline Send Email
Dec 9, 2003
12:15 am

... For reference, here's an example of a 2.30 square root function: http://www.worldserver.com/turk/opensource/FractSqrt.c.txt ... The given code gives...
Damian Yerrick
yerricde
Offline Send Email
Dec 9, 2003
4:02 am

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...
Thomas
SorcererXIII
Offline Send Email
Dec 9, 2003
3:32 pm

Ok, testing has revealed that the bios function is a good 10 times faster than the 2.30 function (I didn't measure it precisely - all I need to know is that...
Thomas
SorcererXIII
Offline Send Email
Dec 9, 2003
4:31 pm

Do bear in mind that if you test the speed of the BIOS functions on an emulator the result will not necessarily be indicative of what happens on real hardware....
Graham Wall
prizeonion
Offline Send Email
Dec 9, 2003
5:40 pm

You are right, what an idiot I am ('specially considering that I did that very thing two years ago when emulating bios for cowbite). I need to get more sleep....
Thomas
SorcererXIII
Offline Send Email
Dec 9, 2003
10:12 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help