ARITHMETICS

As we saw before, numbers are special Atoms in LISP. LISP provides some functions to manipulate numbers, and deal with several different representations for the numbers. Such representations can be divided into four main categories: Integer, Float-point, ratios and complex.

Usually, all numeric functions accept any kind of numbers; they are generic but other numeric function accept only certain kind of numbers.

This part will be more emphasis with the integer and float-point numbers; in some cases we need to force the execution of a floating-point operation, instead of an integer operation (by default). It can be done involving at least one floating-point number in such operation and LISP will realize that you want to use this specific type in the operation. Notice, that the internal representation of a integer will be different than the same integer followed by a period.

Some Functions,


PREDICATES IN NUMBERS

Each one of the following functions requires that its argument be a number and return a Boolean expression.

COMPARISON IN NUMBERS

The following functions require that its arguments have to be numbers; call one with a non-number argument is an error. Unless otherwise specified, each one works on all types of numbers (integer, float-point, etc.),automatically performing any required coercion when arguments are of different types.

All of them return a Boolean expression.

The general format is:

( function number OPTIONAL more-numbers )

Functions

(= number more-numbers)
(/= number more-numbers)
(< number more-numbers)
(> number more-numbers)
(<= number more-numbers)
(> = number more-numbers)

With two arguments these functions perform the usual arithmetic comparison test.

With three or more arguments they are useful for range checks as shows in the following example:

(<= 0 x 10   ) True if x is between 0 and 10, inclusive.
(<= 0 3 4 4 6) True.
(< 0.0 x 10.0) True if x is between 0 and 10, Exclusive.
(< 0 3 4 4 6 ) False.

ARITHMETIC OPERATIONS

Each one of these functions require that its arguments all be numbers; call one with a non-number argument is an error. Unless otherwise specified, each one works on all type of numbers (integer, float-point, etc.),automatically performing any required coercion when arguments are of different types.


MORE MATHEMATICS FUNCTIONS...