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:
Does the operand have to be an integer?> (abs 12) 12 > (abs -13) 13 > (abs 0) 0
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