User Tools

====== Function SQRT, ISQRT ====== ====Syntax==== * **sqrt** //number// → //root// * **isqrt** //natural// → //natural-root// ====Arguments and Values==== * //number//, //root// - a //[[CL:Glossary:number]]//. * //natural//, //natural-root// - a non-negative //[[CL:Glossary:integer]]//. ====Description==== **sqrt** and **isqrt** compute square roots. **sqrt** returns the //[[CL:Glossary:principal]]// square root of //number//. If the //number// is not a //[[CL:Glossary:complex]]// but is negative, then the result is a //[[CL:Glossary:complex]]//. **isqrt** returns the greatest //[[CL:Glossary:integer]]// less than or equal to the exact positive square root of //natural//. If //number// is a positive //[[CL:Glossary:rational]]//, it is //[[CL:Glossary:implementation-dependent]]// whether //root// is a //[[CL:Glossary:rational]]// or a //[[CL:Glossary:float]]//. If //number// is a negative //[[CL:Glossary:rational]]//, it is //[[CL:Glossary:implementation-dependent]]// whether //root// is a //[[CL:Glossary:complex rational]]// or a //[[CL:Glossary:complex float]]//. The mathematical definition of complex square root (whether or not minus zero is supported) follows: <blockquote> (sqrt //x//) = ([[CL:Functions:exp]] ([[CL:Functions:math-divide|/]] ([[CL:Functions:log]] //x//) 2)) </blockquote> The branch cut for square root lies along the negative real axis, continuous with quadrant II. The range consists of the right half-plane, including the non-negative imaginary axis and excluding the negative imaginary axis. ====Examples==== <blockquote> (sqrt 9.0) <r>3.0 </r> (sqrt -9.0) <r>#C(0.0 3.0) </r> (isqrt 9) <r>3 </r> (sqrt 12) <r>3.4641016 </r> (isqrt 12) <r>3 </r> (isqrt 300) <r>17 </r> (isqrt 325) <r>18 </r> (sqrt 25) <r>5 //or// 5.0 </r> (isqrt 25) <r>5 </r> (sqrt -1) <r>#C(0.0 1.0) </r> (sqrt #c(0 2)) <r>#C(1.0 1.0)</r> </blockquote> ====Side Effects==== None. ====Affected By==== None. ====Exceptional Situations==== The //[[CL:Glossary:function]]// **sqrt** should signal **[[CL:Types:type-error]]** if its argument is not a //[[CL:Glossary:number]]//. The //[[CL:Glossary:function]]// **isqrt** should signal **[[CL:Types:type-error]]** if its argument is not a non-negative //[[CL:Glossary:integer]]//. The functions **sqrt** and **isqrt** might signal **[[CL:Types:arithmetic-error]]**. ====See Also==== * **[[CL:Functions:exp|Function EXP]]** * **[[CL:Functions:log|Function LOG]]** * {\secref\FloatSubstitutability} ====Notes==== **isqrt** may be defined as follows, although in real //[[CL:Glossary:implementation|implementations]]// this function might be potentially more efficient. <blockquote> ([[CL:Macros:defun]] isqrt (x) ([[CL:Functions:values]] ([[CL:Functions:floor]] (sqrt x)))) </blockquote> \issue{IEEE-ATAN-BRANCH-CUT:SPLIT}