The Grinnell Scheme Web: The abs procedure

What is the absolute value of a number?

It's how far that number is from 0. Sometimes it's called the magnitude of the number. A positive number is equal to its absolute value; a negative number is the negative of its absolute value:

> (abs 12)
12
> (abs -13)
13
> (abs 0)
0
Does the operand have to be an integer?

No, it can be a rational or a real, if the implementation supports such numbers. (A different procedure, magnitude, is provided for complex numbers, if the implementation supports them.)

Does abs always take exactly one operand?

That's right. Giving it any other number of arguments is an error; your program will halt.


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/abs.html


created June 24, 1995
last revised December 26, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)