abs - compute the absolute value of the argument
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(import (rnrs arithmetic flonums)) ;R6RS
(abs number)
(flabs number)
Returns the absolute value of number. This is only defined for real
numbers.
Returns a single value; a number. The flonum variant always returns a flonum.
(abs -47) => 47
(flabs -0.0) => 0.0
(abs -inf.0) => +inf.0
Except for differences in error handling and which types of numbers are
supported, these procedures work the same everywhere.
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. In particular, number must be a real number and for the
flonum variant it must be a flonum.
- 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.
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
In R2RS and R3RS the abs procedure accepted a complex number and returned
its magnitude. Scheme earlier than R2RS, running on MacLISP, had access to the
abs subroutine that accepted a real number. LISP 1.5 does not seem to
have had this function but an example definition is given as an M-expression
in the LISP 1.5 Programmer's Manual.