ARITHMETIC FUNCTIONS


Warning: integer and ratio calculations that overflow become floating point values as part of the math extension, but give no error otherwise. On systems with IEEE floating point, the values +INF and -INF result from overflowing floating point calculations.

The math extension option adds complex numbers, ratios, new functions, and additional functionality to some existing functions. Because of the size of the extension, and the performance loss it entails, some users may not wish to include it. This section documents the math functions both with and without the extension.

Functions that are described as having floating point arguments (SIN COS TAN ASIN ACOS ATAN EXPT EXP SQRT) will take arguments of any type (real or complex) when the math extension is used. In the descriptions, "rational number" means integer or ratio only, and "real number" means floating point number or rational only.

Any rational results are reduced to canonical form (the gcd of the numerator and denominator is 1, the denominator is positive); integral results are reduced to integers. Integer complex numbers with zero imaginary parts are reduced to integers.


TRUNCATES TOWARD ZERO

(truncate <expr> <denom>)

ROUNDS TOWARD NEAREST EVEN INTEGER

(round <expr> <denom>)

TRUNCATES TOWARD NEGATIVE INFINITY

(floor <expr> <denom>)

TRUNCATES TOWARD INFINITY

(ceiling <expr> <denom>)

Round, floor, and ceiling, and the second argument of truncate, are part of the math extension. Results too big to be represented as integers are returned as floating point numbers as part of the math extension. Integers are returned as is.


CONVERTS AN INTEGER TO A FLOATING POINT NUMBER

(
float <expr>)


CONVERTS A REAL NUMBER TO A RATIONAL

(
rational <expr>)

Floating point numbers too large to express return the floating point number, while numbers too small to express return zero. Rational numbers are returned as is.


ADD A LIST OF NUMBERS

(
+ [<expr>...])

With no arguments returns addition identity, 0 (integer)


SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER

(
- <expr>...)


MULTIPLY A LIST OF NUMBERS

(
* [<expr>...])

With no arguments returns multiplication identity, 1


DIVIDE A LIST OF NUMBERS OR INVERT A SINGLE NUMBER

(
/ <expr>...)

With the math extension, division of integer numbers results in a rational quotient, rather than integer. To perform integer division, use TRUNCATE. When an integer complex is divided by an integer, the quotient is floating point complex.


ADD ONE TO A NUMBER

(1+ <expr>)


SUBTRACT ONE FROM A NUMBER

(1- <expr>)


REMAINDER OF A LIST OF NUMBERS

(rem <expr>...)

With the math extension, only two arguments allowed.


NUMBER MODULO ANOTHER NUMBER

(
mod <expr1> <expr2>)

Part of math extension.


THE SMALLEST OF A LIST OF NUMBERS

(
min <expr>...)


THE LARGEST OF A LIST OF NUMBERS

(
max <expr>...)


THE ABSOLUTE VALUE OF A NUMBER

(
abs <expr>)


GET THE SIGN OF A NUMBER

(
signum <expr>)

Defined in common.lsp


COMPUTE THE GREATEST COMMON DIVISOR

(
gcd [<n>...])

With no arguments returns 0, with one argument returns the argument.


COMPUTE THE LEAST COMMON MULTIPLE

(
lcm <n>...)

Part of math extension. A result which would be larger than the largest integer causes an error.


COMPUTE A PSEUDO-RANDOM NUMBER

(
random <n> [<state>])


CREATE A RANDOM-STATE

(
make-random-state [<state>])


COMPUTE THE SINE OF A NUMBER

(
sin <expr>)

COMPUTE THE COSINE OF A NUMBER

(cos <expr>)

COMPUTE THE TANGENT OF A NUMBER

(tan <expr>)

COMPUTE THE ARC SINE OF A NUMBER

(asin <expr>)

COMPUTE THE ARC COSINE OF A NUMBER

(acos <expr>)


COMPUTE THE ARC TANGENT OF A NUMBER

(
atan <expr> [<expr2>])


COMPUTE THE HYPERBOLIC SINE OF A NUMBER

(
sinh <expr>)

COMPUTE THE HYPERBOLIC COSINE OF A NUMBER

(cosh <expr>)

COMPUTE THE HYPERBOLIC TANGENT OF A NUMBER

(tanh <expr>)

COMPUTE THE HYPERBOLIC ARC SINE OF A NUMBER

(asinh <expr>)

COMPUTE THE HYPERBOLIC ARC COSINE OF A NUMBER

(acosh <expr>)

COMPUTE THE HYPERBOLIC ARC TANGENT OF A NUMBER

(atanh <expr>)

Defined in common.lsp


COMPUTE X TO THE Y POWER

(
expt <x-expr> <y-expr>)


COMPUTE E TO THE X POWER

(
exp <x-expr>)


COMPUTE COSINE + I SINE

(
cis <x-expr>)

Defined in common.lsp


COMPUTE THE LOGRITHM

(
log <expr> [<base>])

Part of the math extension


COMPUTE THE SQUARE ROOT OF A NUMBER

(
sqrt <expr>)


GET THE NUMERATOR OF A NUMBER

(
numerator <expr>)

Part of math extension


GET THE DENOMINATOR OF A NUMBER

(
denominator <expr>)

Part of math extension


CONVERT TO COMPLEX NUMBER

(
complex <real> [<imag>])

Part of math extension


GET THE REAL PART OF A NUMBER

(
realpart <expr>)

Part of the math extension


GET THE IMAGINARY PART OF A NUMBER

(
imagpart <expr>)

Part of the math extension


GET THE CONJUGATE OF A NUMBER

(
conjugate <expr>)

Part of the math extension


GET THE PHASE OF A NUMBER

(
phase <expr>)

Part of the math extension


TEST FOR LESS THAN

(
< <n1> <n2>...)

TEST FOR LESS THAN OR EQUAL TO

(<= <n1> <n2>...)

TEST FOR EQUAL TO

(= <n1> <n2>...)

TEST FOR NOT EQUAL TO

(/= <n1> <n2>...)


XLISP-PLUS - Version 2.1g - Tom Almy tom.almy@tek.com - 18 JUL 94
Generated with
WebMaker