View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
SQRT of an 32bit integer |
Posted: Tue Nov 30, 2004 9:14 am |
|
|
SQRT of an 32bit integer
square root sqrt
squareroot
shamlessly stolen from general forum. Looks like it belongs here.
Code: | long uisqrt32(int32 r)
{
int32 t,b,c=0;
for (b=0x10000000;b!=0;b>>=2) {
t = c + b;
c >>= 1;
if (t <= r) {
r -= t;
c += b;
}
}
return(c);
}
|
Last edited by treitmey on Wed Dec 24, 2008 8:45 am; edited 2 times in total |
|
|
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Tue Nov 30, 2004 12:36 pm |
|
|
treitmey,
Did you have opportunity to check it out?
Sorry, I've posted there, but here is the place for it. When I logged in to post the code, you already did.
Marcus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 30, 2004 1:23 pm |
|
|
But you need keywords so people can search for your post.
I'll put them in:
square root
squareroot |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Tue Dec 23, 2008 9:48 pm |
|
|
mvaraujo wrote: | Did you have opportunity to check it out? |
I've just black-box tested it. It seems to be working. The error is on the low side.
Another keyword: sqrt _________________ Read the label, before opening a can of worms. |
|
|
OzanGazi
Joined: 03 Mar 2008 Posts: 6
|
|
Posted: Fri Jan 02, 2009 7:44 am |
|
|
i have just tested the code and its working for 30bit integer max.
Function returns 32767 while r > 30bit..
But why?? |
|
|
|