| sqrt(3scm) | Scheme Programmer's Manual | sqrt(3scm) |
NAME
sqrt, flsqrt - principal square rootLIBRARY
(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).
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, R7RSHISTORY
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://weinholt.se/scheme/manpages/.| 2022-05-08 |