Next: Random Numbers, Previous: Predicates on Numbers, Up: Numbers [Contents][Index]

These functions perform various arithmetic operations on numbers.

- Function:
**abs***number* This function returns the absolute value of

`number`. (Newer versions of Emacs provide this as a built-in function; this package defines`abs`

only for Emacs 18 versions which don’t provide it as a primitive.)

- Function:
**expt***base power* This function returns

`base`raised to the power of`number`. (Newer versions of Emacs provide this as a built-in function; this package defines`expt`

only for Emacs 18 versions which don’t provide it as a primitive.)

- Function:
**gcd***&rest integers* This function returns the Greatest Common Divisor of the arguments. For one argument, it returns the absolute value of that argument. For zero arguments, it returns zero.

- Function:
**lcm***&rest integers* This function returns the Least Common Multiple of the arguments. For one argument, it returns the absolute value of that argument. For zero arguments, it returns one.

- Function:
**isqrt***integer* This function computes the “integer square root” of its integer argument, i.e., the greatest integer less than or equal to the true square root of the argument.

- Function:
**floor****number &optional divisor* This function implements the Common Lisp

`floor`

function. It is called`floor*`

to avoid name conflicts with the simpler`floor`

function built-in to Emacs 19.With one argument,

`floor*`

returns a list of two numbers: The argument rounded down (toward minus infinity) to an integer, and the “remainder” which would have to be added back to the first return value to yield the argument again. If the argument is an integer`x`, the result is always the list`(`

. If the argument is an Emacs 19 floating-point number, the first result is a Lisp integer and the second is a Lisp float between 0 (inclusive) and 1 (exclusive).`x`0)With two arguments,

`floor*`

divides`number`by`divisor`, and returns the floor of the quotient and the corresponding remainder as a list of two numbers. If`(floor*`

returns`x``y`)`(`

, then`q``r`)

, with`q`*`y`+`r`=`x``r`between 0 (inclusive) and`r`(exclusive). Also, note that`(floor*`

is exactly equivalent to`x`)`(floor*`

.`x`1)This function is entirely compatible with Common Lisp’s

`floor`

function, except that it returns the two results in a list since Emacs Lisp does not support multiple-valued functions.

- Function:
**ceiling****number &optional divisor* This function implements the Common Lisp

`ceiling`

function, which is analogous to`floor`

except that it rounds the argument or quotient of the arguments up toward plus infinity. The remainder will be between 0 and minus`r`.

- Function:
**truncate****number &optional divisor* This function implements the Common Lisp

`truncate`

function, which is analogous to`floor`

except that it rounds the argument or quotient of the arguments toward zero. Thus it is equivalent to`floor*`

if the argument or quotient is positive, or to`ceiling*`

otherwise. The remainder has the same sign as`number`.

- Function:
**round****number &optional divisor* This function implements the Common Lisp

`round`

function, which is analogous to`floor`

except that it rounds the argument or quotient of the arguments to the nearest integer. In the case of a tie (the argument or quotient is exactly halfway between two integers), it rounds to the even integer.

- Function:
**mod****number divisor* This function returns the same value as the second return value of

`floor`

.

- Function:
**rem****number divisor* This function returns the same value as the second return value of

`truncate`

.

These definitions are compatible with those in the Quiroz
`cl.el` package, except that this package appends ‘`*`’
to certain function names to avoid conflicts with existing
Emacs 19 functions, and that the mechanism for returning
multiple values is different.

Next: Random Numbers, Previous: Predicates on Numbers, Up: Numbers [Contents][Index]