CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SQRT of an 32bit integer

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

SQRT of an 32bit integer
PostPosted: Tue Nov 30, 2004 9:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 30, 2004 12:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 30, 2004 1:23 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Tue Dec 23, 2008 9:48 pm     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Fri Jan 02, 2009 7:44 am     Reply with quote

i have just tested the code and its working for 30bit integer max.

Function returns 32767 while r > 30bit..

But why??
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group