zackriggle 130 Report post Posted March 17, 2003 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? 0 Share this post Link to post Share on other sites

cowsarenotevil 3006 Report post Posted March 17, 2003 Because C++ does not have the ^ opperator. It only has the realtively slow pow function. -~-The Cow of Darkness-~- 0 Share this post Link to post Share on other sites

n0ob 176 Report post Posted March 17, 2003 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 0 Share this post Link to post Share on other sites

Guest Anonymous Poster Report post Posted March 17, 2003 As far as I know ^ is a bitwise XOR operator. 0 Share this post Link to post Share on other sites

zackriggle 130 Report post Posted March 17, 2003 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. 0 Share this post Link to post Share on other sites

Xai 1848 Report post Posted March 17, 2003 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. 0 Share this post Link to post Share on other sites

Dobbs 164 Report post Posted March 17, 2003 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? 0 Share this post Link to post Share on other sites

YoshiN 122 Report post Posted March 17, 2003 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? 0 Share this post Link to post Share on other sites