Connecting Tech Pros Worldwide Help | Site Map

Square Root function

Newbie
 
Join Date: Dec 2008
Posts: 13
#1: Feb 11 '09
Hi guys,

For some reason, the hardware that i'm working with cannot import sqrt from math. Hence I need to manually write a sqrt function. Been searching everywhere to find such a function but to no avail.

Could any kind soul please help me with this!

THanks a million!

Sam
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,563
#2: Feb 11 '09

re: Square Root function


Good news, Sam! Python has a built-in power operator.
Expand|Select|Wrap|Line Numbers
  1. >>> 2**2
  2. 4
  3. >>> 2**0.5
  4. 1.4142135623730951
  5. >>> 
Newbie
 
Join Date: Dec 2008
Posts: 13
#3: Feb 11 '09

re: Square Root function


Hi,

Thanks for replying! Unfortunately I am using python to program a Telit GSM modem. I write the program on my computer, run it on python, and it works. But as soon as I upload the program into the internal memory of the modem, things go wrong. For one, it cannot work with floats, and apparently sqrt doesn't work too.

Hence I'm trying to manually write a sqrt function to get around the problem.

Thanks for your time!

Regards,
Sam
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,563
#4: Feb 11 '09

re: Square Root function


Sam,

A google search using "square root calculation algorithm" produced a list of several web pages that explains how to calculate a square root manually.
Newbie
 
Join Date: Dec 2008
Posts: 13
#5: Feb 13 '09

re: Square Root function


Hi bvdet,

Thanks for your suggestions! I guess I was googling with the wrong key words that's why I didn't get anything on my first try. Anyway, I've found the webpages that you were talking about to be very useful.

Thanks a million!

Cheers, Sam
Reply