Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Kind of on the topic - I know there is a way to calculate a square root without a calculator. Of course you can do it the "brute force" way, but one day my music teacher told be about a better way, but never explained it in detail. Does someone know how to do this?


I don't want to sound smug or anything, but didn't you study it in school? In Spain we learn it in fifth or sixth grade, just after learning the concept of square root. I thought it was basic enough to be studied at about that age in the rest of the world.

The algorithm is a little complicated compared to other things that we study at that age, but it's not really difficult, although most (and I mean MOST) people, even engineers and such, forget it when they don't need it any more. It infuriates me a little that no teacher explained to us why did it work, but that gave me oportunity to "reverse engineer" the method a few years later, and expand it to a generic n-root algorithm.


> I thought it was basic enough to be studied at about that age in the rest of the world.

Where do you think GP went to school? Neither the post nor the profile indicates a location.

Edit: I should say that I don't know for sure that you don't know from some other post GP made.


I don't know, that's why I just talked about "the rest of the world". I'm just surprised that this is not as common as I thought it was. Cultural blindness, I guess.


Why did you just mock someone for asking an honest question, tell them that you knew the answer, and then refuse to share it?


I'm sorry, that wasn't at all my intention. In any case, I wouldn't be mocking him, but the educational system he studied under (which definitely wouldn't be his fault; to be honest, I've also suffered a quite bad educational system). And I didn't answer him because someone else had done so already in another comment, linking to wikipedia, so I didn't want to be redundant.


We also learned it in, I think, 4th grade or perhaps 5th. This was in the US. And yes, I've also forgotten it. I don't think I ever used the method outside of that lesson.


I guess it's this: if you have a guess G at the square root of N, compute N/G. If G is too large, N/G will be too small and vice versa (well, as long as your initial guess is larger than zero)

Also, G' = (G+N/G)/2 will be a better guess than G.

Iterate.

If that's not it, pick one from http://en.wikipedia.org/wiki/Methods_of_computing_square_roo...


I learned one method in high school. I couldn't remember it, and too lazy to try to work it out, but here are some answers.

http://en.wikipedia.org/wiki/Methods_of_computing_square_roo...


I just want to point out one of the links on that page: http://en.wikipedia.org/wiki/Fast_inverse_square_root

Absolutely hilarious and amazingly magical method of algorithmically computing square roots. It right shifts a floating point number to essentially divide the exponent component by 2. Then it uses a weird magic number trick to get the correct result. Awesome random programming trivia.


Note that this is the inverse square root, i.e. 1/sqrt(x) (which can also be written x^(-1/2) ).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: