Archived

This topic is now archived and is closed to further replies.

zackriggle

sqrt() vs x^0.5

Recommended Posts

zackriggle    130
Now, I understand that the sqrt() function is relatively slow. I also know that there are many ways to go about finding the square root of a number. Why doesn''t everyone just use X^0.5 where X is the number you want to find the square root of? Is it slow?

Share this post


Link to post
Share on other sites
n0ob    176
I don''t think that will work.. My compiler won''t compile if the value to the right of the ^ is a float. When I tried it as a whole number, it kept adding them together instead of performing an exponent operation.. Boggle

Kings of Chaos

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
As far as I know ^ is a bitwise XOR operator.

Share this post


Link to post
Share on other sites
zackriggle    130
I realize that... but it was just a though I stumbled across during Algebra today [we were working on simplifying square roots...

I was just curious.

Share this post


Link to post
Share on other sites
Xai    1848
Let me explain ... just because a things is ONE operation in theoretical math ... does not exactly mean it is one efficient implementation in computer terms ... as saying, why not implement sqrt(x) as x^.5 power implies that they are different ... when as you pointed out they are not ... they are the same thing.

I want to give you a lot of credit for your attitude though, that way of looking at the world will lead you to find certain connections or optimizations others will miss ...

But in this case, the implementor of sqrt() will use whatever method is mathematically fastest ... and since he knows it will ALWAYS be a power of .5, his version will be FASTER than any pow function which takes a float ... because they cannot be optimized for this one case, where sqrt() can.

Share this post


Link to post
Share on other sites
Dobbs    164
Xai, sqrt(x) and x^.5 are different in C/C++, which seems to be what he''s using. Did you mean sqrt(x) and pow(x, 2) are the same?

Share this post


Link to post
Share on other sites
YoshiN    122
I think he meant that in math, sqrt(x) and x^.5 are the same. He then said in C++ that sqrt(x) is optimized since it will always be x^.5 whereas the pow() function has a variable exponent. So basically he said what you just said - sqrt(x) and pow(x, .5) are totally different.

quote:
Original post by Dobbs
Xai, sqrt(x) and x^.5 are different in C/C++, which seems to be what he''s using. Did you mean sqrt(x) and pow(x, 2) are the same?


Share this post


Link to post
Share on other sites