Jump to content
  • Advertisement

Archived

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

PsYcHoPrOg

Square root

This topic is 6589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I''ve asked countless math teachers, professors, and majors, the same thing: How do you get the sqaure root of a number without a calculator, and without guessing? I want to make an algorithm for a simple calculator program. Obviously, it''s possible. Calculators can do it, a desktop can definately do it. But nobody knows how to do it! It''s always "they taught us that a long time ago, but I don''t remember. They don''t teach that anymore. It must''ve been the invention of the calculator..." If anybody knows how I could do this, LET ME KNOW, PLEASE!!!!! "Remember, I'm the monkey, and you're the cheese grater. So no messing around." -Grand Theft Auto, London "It's not whether I win or lose, as long as I piss you off" -Morrigan, Super Puzzle Fighter II Turbo

Share this post


Link to post
Share on other sites
Advertisement
Try Newtons Iteration:

square root







"You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!""


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you do the algebra...

sqrt(x) = y for some number y.
=> x = y^2
=> log(x) = log(y^2), where log is the natural logarithm.
=> log(x) = 2 * log(y)
=> log(y) = log(x) / 2
=> y = exp(log(x)/2) (or e^(log(x)/2)), where exp is the exponential function.

This would be extremely slow of course, but exp and log are defined in math.h.

There is another method explained here:

http://forum.swarthmore.edu/dr.math/problems/steve.8.6.96.html

Share this post


Link to post
Share on other sites
E.g. if we want to calculate sqrt(3), we take e.g. 1 as start value, we get
1. y = (1 + 3/1)/2 = 2
2. y = (2 + 3/2)/2 = 7/4
3. y = (7/4 + 3/(7/4))/2 = ........

Visit our homepage: www.rarebyte.de.st

GA

Edited by - ga on June 20, 2000 8:33:56 AM

Share this post


Link to post
Share on other sites
To calculate any sqrt stuff try this:

y = exp(ln(base)/power);

or

exp(number, 1/base)

[Sorry, Psycho, but after a several conversation with
some people i am no further sure whether this is correct]
-------
pseudo-programmer, webmaster @
digital impulse

Edited by - Wolti on June 22, 2000 9:36:30 AM

Share this post


Link to post
Share on other sites
Thanks for your help, everybody! I appreciate it. Anyone else with suggestions, feel free to add to the thread. I need as many suggestions as I can get.

Share this post


Link to post
Share on other sites
The easiest way to do is by x^(1/2) because:

x = y^2
ln(x) = ln(y^2)
ln(x) = ln(y) * 2
ln(x) / 2 = ln(y)
ln(x) * 1/2 = ln(y)
ln(x^(1/2)) = ln(y)
x^(1/2) = y

BTW, isn''t sqrt in the math.h to??

Share this post


Link to post
Share on other sites
x^(1/2) isnt really a solution.

Like... you can write x^2 as x*x, and you can figure that out with using normal multiplication. But..how do you write x^(1/2) the only way is the sqrt(x)...which is back where you started.

Its true. I mean, x^(1/2) == sqrt(x), but it doesnt really help you figure it out with a pencil and paper.

sorry to be picky

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!