sqrt(3scm)
π sqrt(3scm) β the Scheme Programmer's Manual, but make it cute β¨
okay so bestie, we're doing the sqrt page today, and honestly? it ate. this is sqrt and flsqrt from the Scheme Programmer's Manual, and by the end you're gonna be so comfy with principal square roots it's not even funny. π
πΈ NAME πΈ
sqrt, flsqrt β principal square root
π LIBRARY π
like, where do you even find these icons? here:
(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. that's the whole vibe. π
π Rational arguments
For rational z, the result has either a positive real part, or a zero real part with a non-negative imaginary part. so it's never gonna be out here being messy with a negative real part, no ma'am.
π¦ Non-real arguments
okay so for non-real z, let the value of log z be defined in terms of log on real numbers as:
log z = log |z| + (angle z)i
and then the value of (sqrt z) can be expressed as:
e**((log z)/2)
the way that's just math but make it fashion π
π Exact arguments
heads up bestie β the sqrt procedure may return an inexact result even when given an exact argument. yes, even exact. it's giving "I contain multitudes." π
β 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. so like... unspecified. she's mysterious. π
π§ IMPLEMENTATION NOTES π§
π«Ά Chez Scheme
For exact arguments where the principal square root is an integer, Chez Scheme returns an exact integer. slay, the precision we deserve π₯
π RETURN VALUES π
Returns a single value; a number object. just one. not a list, not a tuple, one number bestie, periodt.
π₯ EXAMPLES π₯
these are, like, the receipts. look at her go:
(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
(sqrt -1) => +i?? the imaginary unit said hi and she ATE. π
πΈ COMPATIBILITY πΈ
The sqrt procedure works mostly the same everywhere. How exact arguments are handled differs between implementations. And important: R7RS implementations are not required to support all number types and may e.g. omit support for complex numbers. so like... check your implementation's vibe before you come for her π
π 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. we do not accept chaos in this house π ββοΈ- 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. yes, catastrophically. she said go big or go home π
π SEE ALSO π
expt(3scm)log(3scm)
the besties of the family, go say hi π«Ά
β STANDARDS β
R4RS, IEEE Scheme, R5RS, R6RS, R7RS β she's certified in literally every era, iconic behavior π
π¦ HISTORY π¦
This procedure first appeared in R2RS, which got it from Common Lisp. so she's old money, lowkey. π
π 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/. thank you for your service π«‘π
and that's the whole page bestie!! this one's from the 2022-05-08 drop of the sqrt(3scm) era, so if you cite it, you cite it correctly. mwah πβ¨ π
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms