Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Integer square root
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Numerical example === For example, if one computes the integer square root of {{math|2000000}} using the algorithm above, one obtains the sequence <math display="block">\begin{align} & 1000000 \rightarrow 500001 \rightarrow 250002 \rightarrow 125004 \rightarrow 62509 \rightarrow 31270 \rightarrow 15666 \rightarrow 7896 \\ & \rightarrow 4074 \rightarrow 2282 \rightarrow 1579 \rightarrow 1422 \rightarrow 1414 \rightarrow 1414 \end{align}</math> In total 13 iteration steps are needed. Although Heron's method converges quadratically close to the solution, less than one bit precision per iteration is gained at the beginning. This means that the choice of the initial estimate is critical for the performance of the algorithm. When a fast computation for the integer part of the [[binary logarithm]] or for the [[bit-length]] is available (like e.g. <code>std::bit_width</code> in [[C++20]]), one should better start at <math display="block">x_0 = 2^{\lfloor (\log_2 n) /2 \rfloor+1},</math> which is the least [[power of two]] bigger than <math>\sqrt n</math>. In the example of the integer square root of {{math|2000000}}, <math>\lfloor \log_2 n \rfloor = 20</math>, <math>x_0 = 2^{11} = 2048</math>, and the resulting sequence is <math display="block">2048 \rightarrow 1512 \rightarrow 1417 \rightarrow 1414 \rightarrow 1414.</math> In this case only four iteration steps are needed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)