+ 1

sqrt vs pow functions

for example have a different between sqrt(9) and pow(9,1/2)? can we use both of them? which is suitable? ps: i have sqrt problem

24th Jul 2017, 6:25 PM
Farid Zamanov
Farid Zamanov - avatar
4 Answers
+ 3
Use sqrt. They are mathematically the exact same, but since we're talking about computers: In C, sqrt seems to give more precise answers, according to the experiment done by these answers: https://stackoverflow.com/questions/11810686/is-fast-implementation-of-powx-0-5f-faster-than-fast-sqrtx According to another answer there, the sqrt() function performed almost 9x faster. Keep in mind the sqrt function is specifically designed for square roots! Pow is not, and will likely need to do a few more comparisons. (Depending on how it is designed). So sqrt() should be faster and more effecient in practically all languages. Though, both should be fine for the common program (the difference may not matter for you). I also found sqrt() to be way faster in my own tests. (Java). (In EVERY case). https://code.sololearn.com/cpfUWe23IG3o/?ref=app
24th Jul 2017, 11:21 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
They are the same, sqrt finds the square root and if you remember from the laws of indeces in math A^1/n is same as root n for A, also saying A^1/3 is same as cube root of A
24th Jul 2017, 7:23 PM
LordGhostX
LordGhostX - avatar
+ 1
not sure but I think both are same.
24th Jul 2017, 6:55 PM
Akash
Akash - avatar
+ 1
or u can say pow(9/0.5)
24th Jul 2017, 8:58 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar