sqrt(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’– 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