Is there an algorithm to find the square root of a given number using bitwise operations?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is this famous piece of code magic that computes inverse square root with a some very clever bit twiddling. It is wrongfully attributed to John Carmack – here’s a deeper dig into its origin. Maybe that’s what you’re asking about?
I wouldn’t suggest using it, though. On modern CPU’s it cannot beat dedicated transcendental instructions. Your usual c++ intrinsic
sqrt()would probably beat it hands down.[Edit:] The cited article describes a general derivation method for such fast approximations, and explicitly states ‘Derive a similar method for sqrt(x)’ as a homework problem at its final lines. So you should be able to track its reasoning and devise a similar method for sqrt (without the reciprocal) directly.