Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform square root without using math module?

Tags:

python

I want to find the square root of a number without using the math module,as i need to call the function some 20k times and dont want to slow down the execution by linking to the math module each time the function is called

Is there any faster and easier way for finding square root?

like image 200
kaki Avatar asked Jun 15 '10 16:06

kaki


People also ask

How do you get the square root without using language math API provided function?

if you need to find square root without using sqrt() ,use root=pow(x,0.5) . Where x is value whose square root you need to find. Save this answer.


1 Answers

Importing the math module only happens once, and you probably won't get much faster than the math module. There is also an older Stackoverflow question regarding Which is faster in Python: x**.5 or math.sqrt(x)?. It is not clear which method is faster.

Maybe take a look at NumPy and SciPy, not necessarily for the sqrt but if you're doing some heavy calculations they could be handy.

like image 84
Mad Scientist Avatar answered Sep 30 '22 20:09

Mad Scientist