Each of the functions in this section requires that its arguments all be numbers; to call one with a non-number is an error. Unless otherwise specified, each works on all types of numbers, automatically performing any required coercions when arguments are of different types.
This returns the sum of the arguments. If there are no arguments, the result is 0, which is an identity for this operation.
The function -, when given one argument, returns the negative of that argument.
The function -, when given more than one argument, successively subtracts from the first argument all the others, and returns the result. For example, (- 3 4 5) ⇒ -6.
This returns the product of the arguments. If there are no arguments, the result is 1, which is an identity for this operation.
The function /, when given more than one argument, successively divides the first argument by all the others and returns the result.
It is generally accepted that it is an error for any argument other than the first to be zero.
With one argument, / reciprocates the argument.
It is generally accepted that it is an error in this case for the argument to be zero.
/ will produce a ratio if the mathematical quotient of two integers is not an exact integer. For example:
To divide one integer by another producing an integer result, use one of the functions floor, ceiling, truncate, or round.
If any argument is a floating-point number, then the rules of floating-point contagion apply.
(1+ x) is the same as (+ x 1).
(1- x) is the same as (- x 1). Note that the short name may be confusing: (1- x) does not mean 1 −x; rather, it means x − 1. ____________________________
Implementation note: Compiler writers are very strongly encouraged to ensure that (1+ x) and (+ x 1) compile into identical code, and similarly for (1- x) and (- x 1), to avoid pressure on a Lisp programmer to write possibly less clear code for the sake of efficiency. This can easily be done as a source-language transformation.
The number produced by the form delta is added to (incf) or subtracted from (decf) the number in the generalized variable named by place, and the sum is stored back into place and returned. The form place may be any form acceptable as a generalized variable to setf. If delta is not supplied, then the number in place is changed by 1. For example:
The effect of (incf place delta) is roughly equivalent to
except that the latter would evaluate any subforms of place twice, whereas incf takes care to evaluate them only once. Moreover, for certain place forms incf may be significantly more efficient than the setf version.
This returns the complex conjugate of number. The conjugate of a non-complex number is itself. For a complex number z,
For example:
This returns the greatest common divisor of all the arguments, which must be integers. The result of gcd is always a non-negative integer. If one argument is given, its absolute value is returned. If no arguments are given, gcd returns 0, which is an identity for this operation. For three or more arguments,
Here are some examples of the use of gcd:
This returns the least common multiple of its arguments, which must be integers. The result of lcm is always a non-negative integer. For two arguments that are not both zero,
If one or both arguments are zero,
For one argument, lcm returns the absolute value of that argument. For three or more arguments,
Some examples:
(lcm) ought to have been defined to return 1.