sqrt, flsqrt - principal square root
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme inexact)) ;R7RS
(flsqrt fl) ;R6RS
Returns the principal square root of
- Rational arguments
the result has either positive real part, or zero real part
and non-negative imaginary part.
- Non-real arguments
Let the value of log z for non-real z be defined in terms of log on
real numbers as
log z = log |z| + (angle z)i
The value of (sqrt z) can then be expressed as
- Exact arguments
procedure may return an inexact result even when given an exact
- Flonum variant
returns the principal square root of
For -0.0 it should return −0.0; for other negative arguments, the
result may be a NaN or some unspecified flonum.
- Chez Scheme
For exact arguments where the principal square root is an integer,
Chez Scheme returns an exact integer.
Returns a single value; a number object.
(sqrt 9) => 3
(sqrt -1) => +i
(sqrt -5) => 0.0+2.23606797749979i ; approximately
(sqrt +inf.0) => +inf.0
(sqrt -inf.0) => +inf.0i
(flsqrt +inf.0) => +inf.0
(flsqrt -0.0) => -0.0
procedure works mostly the same everywhere. How exact arguments are
handled differs between implementations. R7RS implementations are not
required to support all number types and may e.g. omit support for
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
This procedure first appeared in R2RS, which got it from Common Lisp.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.