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!
===Linear search using addition=== In the program above (linear search, ascending) one can replace multiplication by addition, using the equivalence <math display="block">(L+1)^2 = L^2 + 2L + 1 = L^2 + 1 + \sum_{i=1}^L 2.</math> <syntaxhighlight lang="c" line="1"> // Integer square root // (linear search, ascending) using addition unsigned int isqrt(unsigned int y) { unsigned int L = 0; unsigned int a = 1; unsigned int d = 3; while (a <= y) { a = a + d; // (a + 1) ^ 2 d = d + 2; L = L + 1; } return L; } </syntaxhighlight>
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)