abs(3scm)

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

πŸ’– abs(3scm) β€” Scheme Programmer's Manual πŸ’–

okay bestie, so this one is from the Scheme Programmer's Manual (the 3scm bit, iykyk) and it's genuinely one of the most chill little procedures out there. let's get into it 🫢


🌸 NAME 🌸

abs β€” literally just computes the absolute value of the argument. that's it. that's the whole vibe ✨


πŸŽ€ LIBRARY πŸŽ€

here's where you can find it, depending on which flavour of Scheme you're living in:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS
(import (rnrs arithmetic flonums))  ;R6RS

the last one is only for the flonum variant, slay πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

(abs number)
(flabs number)

✨ DESCRIPTION ✨

abs returns the absolute value of number. super simple, no cap. the one catch β€” and this is important β€” it's only defined for real numbers. so don't come at it with a complex number and expect main character energy, ok? πŸ™ˆ


πŸ’œ RETURN VALUES πŸ’œ

returns a single value: a number. one and done. the flonum variant (flabs) always returns a flonum β€” it's committed to the bit, periodt πŸ”₯


🌈 EXAMPLES 🌈

look at these little icons go:

(abs -47)     =>  47
(flabs -0.0)  =>  0.0
(abs -inf.0)  =>  +inf.0

-0.0 becoming 0.0 is honestly giving attention to detail πŸ’… and infinity flipping to positive infinity? iconic.


πŸŽ€ COMPATIBILITY πŸŽ€

okay so apart from differences in error handling and which types of numbers are supported, these procedures work the same everywhere. so if you switch implementations, the math still maths 🫢


πŸ’€ ERRORS πŸ’€

this procedure can raise exceptions with the following condition types β€” pay attention bestie:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. in particular, number must be a real number, and for the flonum variant it must be a flonum. no exceptions (except the exceptions, lol 😭).
  • 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. so like, be normal about your arguments please πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

  • magnitude(3scm) β€” the cousin that actually does the complex-number thing πŸ‘‘

⭐ STANDARDS ⭐

R4RS, IEEE Scheme, R5RS, R6RS, R7RS β€” literally certified by everyone, we love a broadly-adopted queen πŸŒˆπŸ‘‘


🧚 HISTORY 🧚

story time πŸ“ back in R2RS and R3RS, abs accepted a complex number and returned its magnitude. so it was out here doing the most. Scheme earlier than R2RS, running on MacLISP, had access to the abs subroutine that accepted a real number. and LISP 1.5? doesn't seem to have had this function at all β€” though an example definition is given as an M-expression in the LISP 1.5 Programmer's Manual. the lore is deep, fr fr πŸ’œ


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


and that's the tea, bestie πŸŽ€ this page walked so you could (abs -47) with confidence. catch you on 2023-02-14 β€” mwah πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from