#### Archived

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

# sqrt() vs x^0.5

## Recommended Posts

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 on other sites
Because C++ does not have the ^ opperator. It only has the realtively slow pow function.

-~-The Cow of Darkness-~-

##### Share on other sites
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 on other sites
As far as I know ^ is a bitwise XOR operator.

##### Share on other sites
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 on other sites
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 on other sites
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 on other sites
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?

• ### Forum Statistics

• Total Topics
628354
• Total Posts
2982243

• 10
• 9
• 11
• 24
• 11