sqrt, flsqrt - principal square root
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme inexact)) ;R7RS
SYNOPSIS
(sqrt z)
(flsqrt fl) ;R6RS
DESCRIPTION
Returns the principal square root of
z.
- Rational arguments
-
For rational
z,
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
e**((log z)/2).
- Exact arguments
-
The
sqrt
procedure may return an inexact result even when given an exact
argument.
- Flonum variant
-
flsqrt
returns the principal square root of
fl.
For -0.0 it should return −0.0; for other negative arguments, the
result may be a NaN or some unspecified flonum.
IMPLEMENTATION NOTES
- Chez Scheme
-
For exact arguments where the principal square root is an integer,
Chez Scheme returns an exact integer.
RETURN VALUES
Returns a single value; a number object.
EXAMPLES
(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
COMPATIBILITY
The
sqrt
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
complex numbers.
ERRORS
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.
- R7RS
-
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.
SEE ALSO
expt(3scm),
log(3scm)
STANDARDS
R4RS,
IEEE Scheme,
R5RS,
R6RS,
R7RS
HISTORY
This procedure first appeared in R2RS, which got it from Common Lisp.
AUTHORS
This page is part of the
scheme-manpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
Markup created by unroff 1.0sc, March 04, 2023.