Function abs

Syntax:

abs number absolute-value

Arguments and Values:

number—a number.

absolute-value—a non-negative real.

Description:

12.5.2 3abs returns the absolute value of number. 12.5.2 4

If number is a real, the result is of the same type as number.

If number is a complex, the result is a positive real with the same magnitude as number. The result can be a float Reviewer: Barmar: Single-float.!!! What to do here? -kmp 17-Dec-90even if number's components are rationals and an exact rational result would have been possible. 12.5.2 7Thus the result of (abs #c(3 4)) can be either 5 or 5.0, depending on the implementation.

Examples:

 (abs 0) → 0
 (abs 12/13) → 12/13
 (abs -1.09) → 1.09
 (abs #c(5.0 -5.0)) → 7.071068
 (abs #c(5 5)) → 7.071068
 (abs #c(3/5 4/5)) → 1 or approximately 1.0
 (eql (abs -0.0) -0.0) → true

Affected By:

None.

Exceptional Situations:

None.

See Also:

Section 12.1.3.3 (Rule of Float Substitutability)

Notes:

12.5.2 5If number is a complex, the result is equivalent to the following: \hfil\break

(sqrt (+ (expt (realpart number) 2) (expt (imagpart number) 2))) Barmar says ``SQRT is a defined name, so there's no need to redefine it here.'' -kmp 17-Dec-90 , where \issue{IEEE-ATAN-BRANCH-CUT:SPLIT} \f{(sqrt \i{x}) = (exp (/ (log \i{x}) 2))} \endissue{IEEE-ATAN-BRANCH-CUT:SPLIT}

12.5.2 6An implementation should not use this formula directly for all complexes but should handle very large or very small components specially to avoid intermediate overflow or underflow.