abs(3scm)
π 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms