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.
- <expr> the real number
- <denom> real number to divide <expr> by before converting
- returns the integer result of converting the number, and, as a second return value, the remainder of the operation, defined as expr - result*denom. the type is float if either argument is float, otherwise it is rational.
CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
(float <expr>)
- <expr> the real number
- returns the number as a floating point number
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.
- <expr> the real number
- returns the number as a ratio or integer.
ADD A LIST OF NUMBERS
(+ [<expr>...])
With no arguments returns addition identity, 0 (integer)
- <expr> the numbers
- returns the result of the addition
SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
(- <expr>...)
- <expr> the numbers
- returns the result of the subtraction
MULTIPLY A LIST OF NUMBERS
(* [<expr>...])
With no arguments returns multiplication identity, 1
- <expr> the numbers
- returns the result of the multiplication
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.
- <expr> the numbers
- returns the result of the division
ADD ONE TO A NUMBER
(1+ <expr>)
- <expr> the number
- returns the number plus one
SUBTRACT ONE FROM A NUMBER
(1- <expr>)
- <expr> the number
- returns the number minus one
REMAINDER OF A LIST OF NUMBERS
(rem <expr>...)
With the math extension, only two arguments allowed.
- <expr> the real numbers (must be integers, without math extension)
- returns the result of the remainder operation (remainder with truncating division)
NUMBER MODULO ANOTHER NUMBER
(mod <expr1> <expr2>)
Part of math extension.
- <expr1> real number
- <expr2> real number divisor (may not be zero)
- returns the remainder after dividing <expr1> by <expr2> using flooring division, thus there is no discontinuity in the function around zero.
THE SMALLEST OF A LIST OF NUMBERS
(min <expr>...)
- <expr> the real numbers
- returns the smallest number in the list
THE LARGEST OF A LIST OF NUMBERS
(max <expr>...)
- <expr> the real numbers
- returns the largest number in the list
THE ABSOLUTE VALUE OF A NUMBER
(abs <expr>)
- <expr> the number
- returns the absolute value of the number, which is the floating point magnitude for complex numbers.
GET THE SIGN OF A NUMBER
(signum <expr>)
Defined in common.lsp
- <expr> the number
- returns zero if number is zero, one if positive, or negative one if negative. Numeric type is same as number. For a complex number, returns unit magnitude but same phase as number.
COMPUTE THE GREATEST COMMON DIVISOR
(gcd [<n>...])
With no arguments returns 0, with one argument returns the argument.
- <n> The number(s) (integer)
- returns the greatest common divisor
COMPUTE THE LEAST COMMON MULTIPLE
(lcm <n>...)
Part of math extension. A result which would be larger than the largest integer causes an error.
- <n> The number(s) (integer)
- returns the least common multiple
COMPUTE A PSEUDO-RANDOM NUMBER
(random <n> [<state>])
- <n> the real number upper bound
- <state> a random-state (default is *random-state*)
- returns a random number in range [0,n)
CREATE A RANDOM-STATE
(make-random-state [<state>])
- <state> a random-state, t, or NIL (default NIL). NIL means *random-state*
- returns If <state> is t, a random random-state, otherwise a copy of <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>)
- <expr> the floating point number
- returns the sine, cosine, tangent, arc sine, or arc cosine of the number
COMPUTE THE ARC TANGENT OF A NUMBER
(atan <expr> [<expr2>])
- <expr> the floating point number (numerator)
- <expr2> the denominator, default 1. May only be specified if math extension installed
- returns the arc tangent of <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
- <expr> the number
- returns the hyperbolic sine, cosine, tangent, arc sine, arc cosine, or arc tangent of the number.
COMPUTE X TO THE Y POWER
(expt <x-expr> <y-expr>)
- <x-expr> the number
- <y-expr> the exponent
- returns x to the y power. If y is a fixnum, then the result type is the same as the type of x, unless fixnum or ratio and it would overflow, then the result type is a flonum.
COMPUTE E TO THE X POWER
(exp <x-expr>)
- <x-expr> the floating point number
- returns e to the x power
COMPUTE COSINE + I SINE
(cis <x-expr>)
Defined in common.lsp
- <x-expr> the number
- returns e to the ix power
COMPUTE THE LOGRITHM
(log <expr> [<base>])
Part of the math extension
- <expr> the number
- <base> the base, default is e
- returns log base <base> of <expr>
COMPUTE THE SQUARE ROOT OF A NUMBER
(sqrt <expr>)
- <expr> the number
- returns the square root of the number
GET THE NUMERATOR OF A NUMBER
(numerator <expr>)
Part of math extension
- <expr> rational number
- returns numerator of number (number if integer)
GET THE DENOMINATOR OF A NUMBER
(denominator <expr>)
Part of math extension
- <expr> rational number
- returns denominator of number (1 if integer)
CONVERT TO COMPLEX NUMBER
(complex <real> [<imag>])
Part of math extension
- <real> real number real part
- <imag> real number imaginary part (default 0)
- returns the complex number
GET THE REAL PART OF A NUMBER
(realpart <expr>)
Part of the math extension
- <expr> the number
- returns the real part of a complex number, or the number itself if a real number
GET THE IMAGINARY PART OF A NUMBER
(imagpart <expr>)
Part of the math extension
- <expr> the number
- returns the imaginary part of a complex number, or zero of the type of the number if a real number.
GET THE CONJUGATE OF A NUMBER
(conjugate <expr>)
Part of the math extension
- <expr> the number
- returns the conjugate of a complex number, or the number itself if a real number.
GET THE PHASE OF A NUMBER
(phase <expr>)
Part of the math extension
- <expr> the number
- returns the phase angle, equivalent to (atan (imagpart <expr>) (realpart <expr>))
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>...)
- <n1> the first real number to compare
- <n2> the second real number to compare
- returns the result of comparing <n1> with <n2>...
XLISP-PLUS - Version 2.1g - Tom Almy
tom.almy@tek.com - 18 JUL 94
Generated with WebMaker