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
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!
{{short description|Greatest integer less than or equal to square root}} In [[number theory]], the '''integer square root''' (isqrt) of a [[non-negative integer]] {{mvar|n}} is the non-negative integer {{mvar|m}} which is the [[floor function|greatest integer less than or equal]] to the [[square root]] of {{mvar|n}}, <math display="block">\operatorname{isqrt}(n) = \lfloor \sqrt n \rfloor.</math> For example, <math>\operatorname{isqrt}(27) = \lfloor \sqrt{27} \rfloor = \lfloor 5.19615242270663 ... \rfloor = 5.</math> ==Introductory remark== Let <math>y</math> and <math>k</math> be non-negative integers. Algorithms that compute (the [[decimal representation]] of) <math>\sqrt y</math> '''run forever''' on each input <math>y</math> which is not a [[square number|perfect square]].<ref group="note">[[Square root#As decimal expansions|The square roots of the perfect squares (e.g., 0, 1, 4, 9, 16) are integers. In all other cases, the square roots of positive integers are irrational numbers.]]</ref> Algorithms that compute <math>\lfloor \sqrt y \rfloor</math> '''do not run forever'''. They are nevertheless capable of computing <math>\sqrt y</math> up to any desired accuracy <math>k</math>. Choose any <math>k</math> and compute <math display="inline">\lfloor \sqrt {y \times 100^k} \rfloor</math>. '''For example''' (setting <math>y = 2</math>): <math display="block">\begin{align} & k = 0: \lfloor \sqrt {2 \times 100^{0}} \rfloor = \lfloor \sqrt {2} \rfloor = 1 \\ & k = 1: \lfloor \sqrt {2 \times 100^{1}} \rfloor = \lfloor \sqrt {200} \rfloor = 14 \\ & k = 2: \lfloor \sqrt {2 \times 100^{2}} \rfloor = \lfloor \sqrt {20000} \rfloor = 141 \\ & k = 3: \lfloor \sqrt {2 \times 100^{3}} \rfloor = \lfloor \sqrt {2000000} \rfloor = 1414 \\ & \vdots \\ & k = 8: \lfloor \sqrt {2 \times 100^{8}} \rfloor = \lfloor \sqrt {20000000000000000} \rfloor = 141421356 \\ & \vdots \\ \end{align}</math> Compare the results with <math>\sqrt {2} = 1.41421356237309504880168872420969807856967187537694 ...</math> It appears that the multiplication of the input by <math>100^k</math> gives an accuracy of {{mvar|k}} decimal digits.<ref group="note">It is no surprise that the repeated multiplication by {{math|100}} is a feature in {{harvtxt|Jarvis|2006}}</ref> To compute the (entire) decimal representation of <math>\sqrt y</math>, one can execute <math>\operatorname{isqrt}(y)</math> an infinite number of times, increasing <math>y</math> by a factor <math>100</math> at each pass. Assume that in the next program (<math>\operatorname{sqrtForever}</math>) the procedure <math>\operatorname{isqrt}(y)</math> is already defined and — for the sake of the argument — that all variables can hold integers of unlimited magnitude. Then <math>\operatorname{sqrtForever}(y)</math> will print the entire decimal representation of <math>\sqrt y</math>.<ref group="note">The fractional part of square roots of perfect squares is rendered as {{math|000...}}.</ref> <syntaxhighlight lang="c" line="1"> // Print sqrt(y), without halting void sqrtForever(unsigned int y) { unsigned int result = isqrt(y); printf("%d.", result); // print result, followed by a decimal point while (true) // repeat forever ... { y = y * 100; // theoretical example: overflow is ignored result = isqrt(y); printf("%d", result % 10); // print last digit of result } } </syntaxhighlight> The conclusion is that algorithms which compute {{code|isqrt()}} are computationally equivalent to [[Methods of computing square roots|algorithms which compute {{code|sqrt()}}]]. ==Basic algorithms== The '''integer square root''' of a [[non-negative integer]] <math>y</math> can be defined as <math display="block">\lfloor \sqrt y \rfloor = x : x^2 \leq y <(x+1)^2, x \in \mathbb{N}</math> For example, <math>\operatorname{isqrt}(27) = \lfloor \sqrt{27} \rfloor = 5</math> because <math>6^2 > 27 \text{ and } 5^2 \ngtr 27</math>. ===Algorithm using linear search=== The following C programs are straightforward implementations. {{flex columns |1= <syntaxhighlight lang="c"> // Integer square root // (using linear search, ascending) unsigned int isqrt(unsigned int y) { // initial underestimate, L <= isqrt(y) unsigned int L = 0; while ((L + 1) * (L + 1) <= y) L = L + 1; return L; } </syntaxhighlight> |2= <syntaxhighlight lang="c"> // Integer square root // (using linear search, descending) unsigned int isqrt(unsigned int y) { // initial overestimate, isqrt(y) <= R unsigned int R = y; while (R * R > y) R = R - 1; return R; } </syntaxhighlight> }} ===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> ===Algorithm using binary search=== {{Disputed-section|date=May 2025}} [[Binary search algorithm#Linear search|Linear search]] sequentially checks every value until it hits the smallest <math>x</math> where <math>x^2 > y</math>. A speed-up is achieved by using [[Binary search algorithm#Procedure for finding the leftmost element|binary search]] instead. The following C-program is an implementation. <syntaxhighlight lang="c" line="1"> // Integer square root (using binary search) unsigned int isqrt(unsigned int y) { unsigned int L = 0; unsigned int M; unsigned int R = y + 1; while (L != R - 1) { M = (L + R) / 2; if (M * M <= y) L = M; else R = M; } return L; } </syntaxhighlight> '''Numerical example''' For example, if one computes <math>\operatorname{isqrt}(2000000)</math> using binary search, one obtains the <math>[L,R]</math> sequence <math display="block">\begin{align} & [0,2000001] \rightarrow [0,1000000] \rightarrow [0,500000] \rightarrow [0,250000] \rightarrow [0,125000] \rightarrow [0,62500] \rightarrow [0,31250] \rightarrow [0,15625] \\ & \rightarrow [0,7812] \rightarrow [0,3906] \rightarrow [0,1953] \rightarrow [976,1953] \rightarrow [976,1464] \rightarrow [1220,1464] \rightarrow [1342,1464] \rightarrow [1403,1464] \\ & \rightarrow [1403,1433] \rightarrow [1403,1418] \rightarrow [1410,1418] \rightarrow [1414,1418] \rightarrow [1414,1416] \rightarrow [1414,1415] \end{align}</math> This computation takes 21 iteration steps, whereas linear search (ascending, starting from <math>0</math>) needs {{val|1414}} steps. ==Algorithm using Newton's method== One way of calculating <math>\sqrt{n}</math> and <math>\operatorname{isqrt}(n)</math> is to use [[Methods_of_computing_square_roots#Heron's method|Heron's method]], which is a special case of [[Newton's method]], to find a solution for the equation <math>x^2 - n = 0</math>, giving the iterative formula <math display="block">x_{k+1} = \frac{1}{2}\!\left(x_k + \frac{n}{x_k}\right), \quad k \ge 0, \quad x_0 > 0.</math> The [[sequence]] <math>\{x_k\}</math> [[limit of a sequence|converges]] [[Rate of convergence|quadratically]] to <math>\sqrt{n}</math> as <math>k\to\infty</math>. ===Stopping criterion=== One can prove{{Citation needed|date=August 2021}} that <math>c=1</math> is the largest possible number for which the stopping criterion <math display="block">|x_{k+1} - x_{k}| < c</math> ensures <math>\lfloor x_{k+1} \rfloor=\lfloor \sqrt n \rfloor</math> in the algorithm above. In implementations which use number formats that cannot represent all [[rational number]]s exactly (for example, floating point), a stopping constant less than 1 should be used to protect against round-off errors. ===Domain of computation=== Although <math>\sqrt{n}</math> is [[irrational number|irrational]] for many <math>n</math>, the sequence <math>\{x_k\}</math> contains only rational terms when <math>x_0</math> is rational. Thus, with this method it is unnecessary to exit the [[field (mathematics)|field]] of rational numbers in order to calculate <math>\operatorname{isqrt}(n)</math>, a fact which has some theoretical advantages. ===Using only integer division=== For computing <math>\lfloor \sqrt n \rfloor</math> for very large integers ''n'', one can use the quotient of [[Euclidean division]] for both of the division operations. This has the advantage of only using integers for each intermediate value, thus making the use of [[floating point]] representations of large numbers unnecessary. It is equivalent to using the iterative formula <math display="block">x_{k+1} = \left\lfloor \frac{1}{2}\!\left(x_k + \left\lfloor \frac{n}{x_k} \right\rfloor \right) \right\rfloor, \quad k \ge 0, \quad x_0 > 0, \quad x_0 \in \mathbb{Z}.</math> By using the fact that <math display="block">\left\lfloor \frac{1}{2}\!\left(x_k + \left\lfloor \frac{n}{x_k} \right\rfloor \right) \right\rfloor = \left\lfloor \frac{1}{2}\!\left(x_k + \frac{n}{x_k} \right) \right\rfloor,</math> one can show that this will reach <math>\lfloor \sqrt n \rfloor</math> within a finite number of iterations. In the original version, one has <math>x_k \ge \sqrt n</math> for <math>k \ge 1</math>, and <math>x_k > x_{k+1}</math> for <math>x_k > \sqrt n</math>. So in the integer version, one has <math>\lfloor x_k \rfloor \ge \lfloor\sqrt n\rfloor</math> and <math>x_k \ge \lfloor x_k \rfloor > x_{k+1} \ge \lfloor x_{k+1}\rfloor</math> until the final solution <math>x_s</math> is reached. For the final solution <math>x_s</math>, one has <math>\lfloor \sqrt n\rfloor\le\lfloor x_s\rfloor \le \sqrt n</math> and <math>\lfloor x_{s+1} \rfloor \ge \lfloor x_s \rfloor</math>, so the stopping criterion is <math>\lfloor x_{k+1} \rfloor \ge \lfloor x_k \rfloor</math>. However, <math>\lfloor \sqrt n \rfloor</math> is not necessarily a [[Fixed point (mathematics)|fixed point]] of the above iterative formula. Indeed, it can be shown that <math>\lfloor \sqrt n \rfloor</math> is a fixed point if and only if <math>n + 1</math> is not a perfect square. If <math>n + 1</math> is a perfect square, the sequence ends up in a period-two cycle between <math>\lfloor \sqrt n \rfloor</math> and <math>\lfloor \sqrt n \rfloor + 1</math> instead of converging. === Example implementation in C === <syntaxhighlight lang="c" line="1"> // Square root of integer unsigned int int_sqrt(unsigned int s) { // Zero yields zero // One yields one if (s <= 1) return s; // Initial estimate (must be too high) unsigned int x0 = s / 2; // Update unsigned int x1 = (x0 + s / x0) / 2; while (x1 < x0) // Bound check { x0 = x1; x1 = (x0 + s / x0) / 2; } return x0; } </syntaxhighlight> === 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. ==Digit-by-digit algorithm== The traditional [[Methods of computing square roots#Digit-by-digit calculation|pen-and-paper algorithm]] for computing the square root <math>\sqrt{n}</math> is based on working from higher digit places to lower, and as each new digit pick the largest that will still yield a square <math>\leq n</math>. If stopping after the one's place, the result computed will be the integer square root. ===Using bitwise operations=== If working in [[base 2]], the choice of digit is simplified to that between 0 (the "small candidate") and 1 (the "large candidate"), and digit manipulations can be expressed in terms of binary shift operations. With <code>*</code> being multiplication, <code><<</code> being left shift, and <code>>></code> being logical right shift, a [[Recursion (computer science)|recursive]] algorithm to find the integer square root of any [[natural number]] is: <syntaxhighlight lang="python" line="1"> def integer_sqrt(n: int) -> int: assert n >= 0, "sqrt works for only non-negative inputs" if n < 2: return n # Recursive call: small_cand = integer_sqrt(n >> 2) << 1 large_cand = small_cand + 1 if large_cand * large_cand > n: return small_cand else: return large_cand # equivalently: def integer_sqrt_iter(n: int) -> int: assert n >= 0, "sqrt works for only non-negative inputs" if n < 2: return n # Find the shift amount. See also [[find first set]], # shift = ceil(log2(n) * 0.5) * 2 = ceil(ffs(n) * 0.5) * 2 shift = 2 while (n >> shift) != 0: shift += 2 # Unroll the bit-setting loop. result = 0 while shift >= 0: result = result << 1 large_cand = ( result + 1 ) # Same as result ^ 1 (xor), because the last bit is always 0. if large_cand * large_cand <= n >> shift: result = large_cand shift -= 2 return result </syntaxhighlight> Traditional pen-and-paper presentations of the digit-by-digit algorithm include various optimizations not present in the code above, in particular the trick of pre-subtracting the square of the previous digits which makes a general multiplication step unnecessary. See {{section link|Methods of computing square roots|Binary numeral system (base 2)}} for an example.<ref>{{cite web | last= Woo |first= C |title= Square root by abacus algorithm (archived) |date = June 1985 | url = http://medialab.freaknet.org/martin/src/sqrt/sqrt.c | archive-url = https://web.archive.org/web/20120306040058/http://medialab.freaknet.org/martin/src/sqrt/sqrt.c | archive-date = 2012-03-06 }}</ref> ==Karatsuba square root algorithm== The Karatsuba square root algorithm is a combination of two functions: a [[Access modifiers|public]] function, which returns the integer square root of the input, and a recursive [[Access modifiers|private]] function, which does the majority of the work. The public function normalizes the actual input, passes the normalized input to the private function, denormalizes the result of the private function, and returns that. The private function takes a normalized input, divides the input bits in half, passes the most-significant half of the input recursively to the private function, and performs some integer operations on the output of that recursive call and the least-significant half of the input to get the normalized output, which it returns. For [[Arbitrary-precision arithmetic|big-integers]] of "50 to 1,000,000 digits", [[Burnikel-Ziegler division|Burnikel-Ziegler Karatsuba division]] and [[Karatsuba algorithm|Karatsuba multiplication]] are recommended by the algorithm's creator.<ref>{{cite web | last = Zimmermann | first = Paul | title = Karatsuba Square Root |date = 1999 <!-- This is the date the document was finished, not the date it was submitted to Inria --> | publisher = [[French Institute for Research in Computer Science and Automation|Inria]] | publication-date = 2006-05-24 | series = Research report #3805 | url = https://inria.hal.science/inria-00072854v1/file/RR-3805.pdf | archive-url = https://web.archive.org/web/20230511212802/https://inria.hal.science/inria-00072854v1/file/RR-3805.pdf | archive-date = 2023-05-11 }}</ref> An example algorithm for 64-bit unsigned integers is below. The algorithm: # Normalizes the input inside {{mono|u64_isqrt}}. # Calls {{mono|u64_normalized_isqrt_rem}}, which requires a normalized input. # Calls {{mono|u32_normalized_isqrt_rem}} with the most-significant half of the normalized input's bits, which will already be normalized as the most-significant bits remain the same. # Continues on recursively until there's an algorithm that's faster when the number of bits is small enough. # {{mono|u64_normalized_isqrt_rem}} then takes the returned integer square root and remainder to produce the correct results for the given normalized {{mono|u64}}. # {{mono|u64_isqrt}} then denormalizes the result. <syntaxhighlight lang="rust" line="1"> /// Performs a Karatsuba square root on a `u64`. pub fn u64_isqrt(mut n: u64) -> u64 { if n <= u32::MAX as u64 { // If `n` fits in a `u32`, let the `u32` function handle it. return u32_isqrt(n as u32) as u64; } else { // The normalization shift satisfies the Karatsuba square root // algorithm precondition "aβ β₯ b/4" where aβ is the most // significant quarter of `n`'s bits and b is the number of // values that can be represented by that quarter of the bits. // // b/4 would then be all 0s except the second most significant // bit (010...0) in binary. Since aβ must be at least b/4, aβ's // most significant bit or its neighbor must be a 1. Since aβ's // most significant bits are `n`'s most significant bits, the // same applies to `n`. // // The reason to shift by an even number of bits is because an // even number of bits produces the square root shifted to the // left by half of the normalization shift: // // sqrt(n << (2 * p)) // sqrt(2.pow(2 * p) * n) // sqrt(2.pow(2 * p)) * sqrt(n) // 2.pow(p) * sqrt(n) // sqrt(n) << p // // Shifting by an odd number of bits leaves an ugly sqrt(2) // multiplied in. const EVEN_MAKING_BITMASK: u32 = !1; let normalization_shift = n.leading_zeros() & EVEN_MAKING_BITMASK; n <<= normalization_shift; let (s, _) = u64_normalized_isqrt_rem(n); let denormalization_shift = normalization_shift / 2; return s >> denormalization_shift; } } /// Performs a Karatsuba square root on a normalized `u64`, returning the square /// root and remainder. fn u64_normalized_isqrt_rem(n: u64) -> (u64, u64) { const HALF_BITS: u32 = u64::BITS >> 1; const QUARTER_BITS: u32 = u64::BITS >> 2; const LOWER_HALF_1_BITS: u64 = (1 << HALF_BITS) - 1; debug_assert!( n.leading_zeros() <= 1, "Input is not normalized: {n} has {} leading zero bits, instead of 0 or 1.", n.leading_zeros() ); let hi = (n >> HALF_BITS) as u32; let lo = n & LOWER_HALF_1_BITS; let (s_prime, r_prime) = u32_normalized_isqrt_rem(hi); let numerator = ((r_prime as u64) << QUARTER_BITS) | (lo >> QUARTER_BITS); let denominator = (s_prime as u64) << 1; let q = numerator / denominator; let u = numerator % denominator; let mut s = (s_prime << QUARTER_BITS) as u64 + q; let mut r = (u << QUARTER_BITS) | (lo & ((1 << QUARTER_BITS) - 1)); let q_squared = q * q; if r < q_squared { r += 2 * s - 1; s -= 1; } r -= q_squared; return (s, r); } </syntaxhighlight> ==In programming languages== Some [[programming language]]s dedicate an explicit operation to the integer square root calculation in addition to the general case or can be extended by libraries to this end. {| class="wikitable" ! Programming language !! Example use !! Version introduced |- | [[Chapel (programming language)|Chapel]] || <code>BigInteger.sqrt(result, n);</code><ref>{{cite web | url = https://chapel-lang.org/docs/modules/standard/BigInteger.html#BigInteger.sqrt | title = BigInteger - Chapel Documentation 2.1 | website = Chapel Documentation - Chapel Documentation 2.1}}</ref><br><code>BigInteger.sqrtRem(result, remainder, n);</code> || Unknown |- | [[Common Lisp]] || <code>(isqrt n)</code><ref>{{cite web | url = http://www.lispworks.com/documentation/lw50/CLHS/Body/f_sqrt_.htm | title = CLHS: Function SQRT, ISQRT | website = Common Lisp HyperSpec (TM)}}</ref> || Unknown |- | [[Crystal (programming language)|Crystal]] || <code>Math.isqrt(n)</code><ref>{{cite web | url = https://crystal-lang.org/api/1.13.2/Math.html#isqrt%28value%3AInt%3A%3APrimitive%29-instance-method | title = Math - Crystal 1.13.2 | website = The Crystal Programming Language API docs}}</ref> || 1.2 |- | [[Java (programming language)|Java]] || <code>n.sqrt()</code><ref>{{cite web | url = https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/math/BigInteger.html#sqrt() | title = BigInteger (Java SE 21 & JDK 21) | website = JDK 21 Documentation}}</ref> (<code>BigInteger</code> only) || 9 |- | [[Julia (programming language)|Julia]] || <code>isqrt(n)</code><ref>{{cite web | url = https://docs.julialang.org/en/v1/base/math/#Base.isqrt | title = Mathematics - The Julia Language | website = Julia Documentation - The Julia Language}}</ref> || 0.3 |- | [[Maple (software)|Maple]] || <code>isqrt(n)</code><ref>{{cite web | url = https://www.maplesoft.com/support/help/maple/view.aspx?path=isqrt | title = iroot- Maple Help | website = Help - Maplesoft}}</ref> || Unknown |- | [[PARI/GP]] || <code>sqrtint(n)</code><ref>{{cite web | url = https://pari.math.u-bordeaux.fr/dochtml/html-stable/Arithmetic_functions.html#sqrtint | title = Catalogue of GP/PARI Functions: Arithmetic functions | website = PARI/GP Development Headquarters}}</ref> || 1.35a<ref>{{cite web | url = http://library.snls.org.sz/archive/science/math/multiplePrecision/pari/ | title = Index of /archive/science/math/multiplePrecision/pari/ | website = PSG Digital Resources | archive-url = https://web.archive.org/web/20241106111659/http://library.snls.org.sz/archive/science/math/multiplePrecision/pari/ | archive-date = 2024-11-06}}</ref> (as <code>isqrt</code>) or before |- | [[Python (programming language)|Python]] || <code>math.isqrt(n)</code><ref>{{cite web | url = https://docs.python.org/3/library/math.html#math.isqrt | title = Mathematical functions | website = Python Standard Library documentation}}</ref> || 3.8 |- | [[Racket (programming language)|Racket]] || <code>(integer-sqrt n)</code><ref>{{cite web | url = https://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._integer-sqrt%29%29 | title = 4.3.2 Generic Numerics | website = Racket Documentation}}</ref><br><code>(integer-sqrt/remainder n)</code> || Unknown |- | [[Ruby (programming language)|Ruby]] || <code>Integer.sqrt(n)</code><ref>{{cite web | url = https://docs.ruby-lang.org/en/master/Integer.html#method-c-sqrt | title = class Integer - RDoc Documentation | website = RDoc Documentation}}</ref> || 2.5.0 |- | [[Rust (programming language)|Rust]] || <code>n.isqrt()</code><ref>{{cite web | url = https://doc.rust-lang.org/std/primitive.i32.html#method.isqrt | title = i32 - Rust | website = std - Rust }}</ref><br><code>n.checked_isqrt()</code><ref>{{cite web | url = https://doc.rust-lang.org/std/primitive.i32.html#method.checked_isqrt | title = i32 - Rust | website = std - Rust }}</ref> || 1.84.0 |- | [[SageMath]] || <code>isqrt(n)</code><ref>{{cite web | url = https://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/integer.html#sage.rings.integer.Integer.isqrt | title = Elements of the ring β€ of integers - Standard Commutative Rings | website = SageMath Documentation}}</ref> || Unknown |- | [[Scheme (programming language)|Scheme]] || <code>(exact-integer-sqrt n)</code><ref>{{cite web | url = https://standards.scheme.org/corrected-r7rs/r7rs-Z-H-8.html#TAG:__tex2page_index_470 | title = Revised<sup>7</sup> Report on the Algorithmic Language Scheme | website = Scheme Standards}}</ref> || R<sup>6</sup>RS |- | [[Tcl]] || <code>isqrt($n)</code><ref>{{cite web | url = https://www.tcl.tk/man/tcl/TclCmd/mathfunc.htm#M22 | title = mathfunc manual page - Tcl Mathematical Functions | website = Tcl/Tk 8.6 Manual}}</ref> || 8.5 |- | [[Zig (programming language)|Zig]] || <code>std.math.sqrt(n)</code><ref>{{cite web | url = https://ziglang.org/documentation/master/std/#std.math.sqrt.sqrt | title = std.math.sqrt.sqrt - Zig Documentation | website = Home ⚡ Zig Programming Language }}</ref> || Unknown |} == See also == * [[Methods of computing square roots]] ==Notes== {{Reflist|group=note}} == References == {{Reflist}} ==External links== {{Refbegin}} *{{cite journal |last= Jarvis |first= Ashley Frazer |journal= Mathematical Spectrum |title= Square roots by subtraction |year= 2006 |volume= 37 |pages= 119β122 |url= http://www.afjarvis.staff.shef.ac.uk/maths/jarvisspec02.pdf }} *{{cite book |last= Minsky |first= Marvin |author-link= Marvin Minsky |title= Computation: Finite and Infinite Machines |chapter= 9. The Computable Real Numbers |url= https://archive.org/details/computationfinit0000mins |url-access= registration |publisher= Prentice-Hall |year= 1967 |isbn= 0-13-165563-9 |oclc= 0131655639 }} *{{cite web |url= http://mathcentral.uregina.ca/RR/database/RR.09.95/grzesina1.html |title= A geometric view of the square root algorithm }} {{Refend}} {{number theoretic algorithms}} [[Category:Number theoretic algorithms]] [[Category:Number theory]] [[Category:Root-finding algorithms]] [[Category:Articles with example C code]] [[Category:Articles with example Python (programming language) code]] [[Category:Articles with example Rust code]]
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)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Disputed-section
(
edit
)
Template:Flex columns
(
edit
)
Template:Harvtxt
(
edit
)
Template:Math
(
edit
)
Template:Mono
(
edit
)
Template:Mvar
(
edit
)
Template:Number theoretic algorithms
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:Section link
(
edit
)
Template:Short description
(
edit
)
Template:Val
(
edit
)