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,
Returns true if the number is zero and Nil otherwise.
Example:
(ZEROP 1.0 ) = Nil (ZEROP 0 ) = T
TRY:
Returns true if the number is strictly greater than zero and Nil otherwise.
Example:
(PLUSP 0.0 ) = Nil (PLUSP 10 ) = T
TRY:
Returns true if the number is odd (not divisible by two) and Nil otherwise.
Example:
(ODDP 2 ) = Nil (ODDP 1 ) = T (ODDP 3.0 ) = ERROR
TRY:
Returns true if the argument integer is even (divisible by two) and Nil otherwise.
Example:
(EVENP 5 ) = Nil (EVENP 12 ) = T (EVENP 8.0 ) = ERROR
TRY:
Returns true if the argument is an integer atom and Nil otherwise.
Example:
(INTEGERP 50.0) = Nil (INTEGERP 12 ) = T (INTEGERP 'a ) = ERROR
TRY:
Returns true if the argument is an float-point atom and Nil otherwise.
Example:
(FLOATP 45 ) = Nil (FLOATP 12.3 ) = T
TRY:
All of them return a Boolean expression.
The general format is:
( function number OPTIONAL 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.
Returns the sum of its arguments.
Example:
(+ 1.0 2.0 3.0 4.0 ) = 10.0 (+ 1 2 3 4 ) = 10 (+) = 0
TRY:
It successively subtracts from the first arguments all the others and returns the result.
Example:
(- 1.0 2.0 3.0 4.0 ) = -8.0 (- 9 2 3 4 ) = 0
TRY:
It returns the product of its arguments.
Example:
(* 1.0 2.0 3.0 4.0 ) = 24.0 (* 2 2 3 4 ) = 48 (*) = 1
TRY:
It successively divides the first argument by all the others and returns the result. With one argument it reciprocates the argument.
Example:
(/ 15 3 ) = 5 (/ 3 4 5 ) = 3/20 (/ -3) = -1/3
If any argument is a float-point number, then the rules of float-point
arguments apply. In order to enforce to produce an integer result we
can use the functions:
TRY:
returns the argument plus one.
Example:
TRY:
Returns the argument minus one. Sometime this notation produces some confusion.
For instance
Example:
TRY:
(1+ 24 ) = 25
(1+ 23.5 ) = 24.5
(1- y) looks like the expression 1 - y,
but it really returns y - 1.
(1- 24 ) = 23
(1- 23.5 ) = 22.5
Returns the maximum number among the arguments.
Example:
(MAX 1 12 -50 ) = 12 (MAX -1 -2 -5 ) = -1
TRY:
Returns the minimum number among the arguments.
Example:
(MIN 1 12 -50 ) = 1 (MIN -1 -2 -5 ) = -5
TRY:
Returns e raised to the power of the argument number, where e is the base of natural logarithm.
Example:
(EXP 1 ) = e
TRY:
Returns Base-number raised to the power of the Power-number.
Example:
(EXPT 10 2 ) = 100 (EXPT 2 3 ) = 8
TRY:
Returns the logarithm of the number in base base-number. The default base is e.
Example:
(LOG 8 2 ) = 3 (LOG 100 2 ) = 10
TRY:
Returns the absolute number of the argument.
Example:
(ABS 16 ) = 16 (ABS -16 ) = 16
TRY:
Returns -1, zero, or 1 according if the number is negative, zero, or positive.
Example:
(SIGNUM 16 ) = 1 (SIGNUM -16 ) = -1 (SIGNUM 0.0) = 0.0
TRY:
Returns the principal square-root of the number.
Example:
(SQRT 16 ) = 4 (SQRT 9 ) = 3
TRY:
Returns the greater inter less than equal to the exact positive square-root of the number.
Example:
(ISQRT 16 ) = 4 (ISQRT 12 ) = 3 (ISQRT 300) = 17
TRY: