+ 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
4 odpowiedzi
+ 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
+ 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
+ 1
not sure but I think both are same.
+ 1
or u can say pow(9/0.5)