Arithmetic Functions

Arithmetic Constants

most-positive-fixnum **

#x1fffffff=536,870,911

most-negative-fixnum **

-#x20000000= -536,870,912

short-float-epsilon **

A floating point number on machines with IEEE floating-point format is represented by 21 bit mantissa with 1 bit sign and 7 bit exponent with 1 bit sign. Therefore, floating point epsilon is \(2^{-21}= 4.768368 \times 10^{-7}\).

single-float-epsilon **

same as short-float-epsilon, \(2^{-21}\).

long-float-epsilon **

same as short-float-epsilon since there is no double or long float. \(2^{-21}\).

pi **

\(\pi\), actually 3.14159203, not 3.14159265.

2pi **

\(2\times \pi\)

pi/2 **

\(\pi/2\)

-pi **

-3.14159203

-2pi **

\(-2\times \pi\)

-pi/2 **

\(\pi/2\)

Arithmetic Predicates

numberp object

T if object is number, namely integer or float. Note that characters are also represented by numbers.

integerp object

T if object is an integer number. A float can be converted to an integer by round, trunc and ceiling functions.

floatp object

T if object is a floating-point number. An integer can be converted to a float by the float function.

zerop number

T if the number is integer zero or float 0.0.

plusp number

equivalent to (\(>\) number 0).

minusp number

equivalent to (\(<\) number 0).

oddp integer

The argument must be an integer. T if integer is odd.

evenp integer

The argument must be an integer. T if integer is an even number.

/= num1 num2 &rest more-numbers

Both num1, num2 and all elements of more-numbers must be numbers. T if no two of its arguments are numerically equal, NIL otherwise.

= num1 num2 &rest more-numbers

Both n1 and n2 and all elements of more-numbers must be numbers. T if n1, n2 and all elements of more-numbers are the same in value, NIL otherwise.

:math:`>` num1 num2 &rest more-numbers

Both n1 and n2 and all elements of more-numbers must be numbers. T if n1, n2 and all elements of more-numbers are in monotonically decreasing order, NIL otherwise. For numerical comparisons with tolerance, use functions prefixed by eps as described in the section [Geometry].

:math:`<` num1 num2 &rest more-numbers

Both n1 and n2 and all elements of more-numbers must be numbers. T if n1, n2 and all elements of more-numbers are in monotonically increasing order, NIL otherwise. For numerical comparisons with tolerance, use functions prefixed by eps as described in the section [Geometry].

:math:`>=` num1 num2 &rest more-numbers

Both n1 and n2 and all elements of more-numbers must be numbers. T if n1, n2 and all elements of more-numbers are in monotonically nonincreasing order, NIL otherwise. For numerical comparisons with tolerance, use functions prefixed by eps as described in the section [Geometry].

:math:`<=` num1 num2 &rest more-numbers

Both n1 and n2 and all elements of more-numbers must be numbers. T if n1, n2 and all elements of more-numbers are in monotonically nondecreasing order, NIL otherwise. For numerical comparisons with tolerance, use functions prefixed by eps as described in the section [Geometry].

Integer and Bit-Wise Operations

Following functions request arguments to be integers.

mod dividend divisor

returns remainder when dividend is divided by divisor. (mod 6 5)=1, (mod -6 5)=-1, (mod 6 -5)=1, (mod -6 -5)=-1.

1- number

\(number-1\) is returned.

1+ number

\(number+1\) is returned.

logand &rest integers

bitwise-and of integers.

logior &rest integers

bitwise-inclusive-or of integers.

logxor &rest integers

bitwise-exclusive-or of integers.

logeqv &rest integers

is equivalent to (lognot (logxor …)).

lognand &rest integers

bitwise-nand of integers.

lognor &rest integers

bitwise-nor of integers.

lognot integer

bit reverse of integer.

logtest integer1 integer2

T if (logand integer1 integer2) is not zero.

logbitp index integer

T if indexth bit of integer (counted from the LSB) is 1, otherwise NIL.

ash integer count

Arithmetic Shift Left. If count is positive, shift direction is left, and if count is negative, integer is shifted to right by abs(count) bits.

ldb target position &optional (width 8)

LoaD Byte. Byte specifier for ldb and dpb does not exist in EusLisp. Use a pair of integers instead. The field of width bits at position within target is extracted. For example, (ldb #x1234 4 4) is 3.

dpb value target position &optional (width 8)

DePosit byte. Width bits of value is put in target at positionth bits from LSB.

Generic Number Functions

+ &rest numbers

returns the sum of numbers.

- num &rest more-numbers

If more-numbers are given, they are subtracted from num. Otherwise, num is negated.

* &rest numbers

returns the product of numbers.

/ num &rest more-numbers

is divided by more-numbers. If only one argument is given, 1.0 is divided by num. The result is an integer if all the arguments are integers, and a float if at least one of the arguments is a float.

abs number

returns absolute number.

round number

rounds to the nearest integer. (round 1.5)=2, (round -1.5)=-2.

floor number

rounds to the nearest smaller integer. (floor 1.5)=1, (floor -1.5)=-2.

ceiling number

rounds to the nearest larger integer. (ceiling 1.5)=2, (ceiling -1.5)=-1.

truncate number

rounds to the absolutely smaller and nearest integer. (truncate 1.5)=1, (truncate -1.5)=-1.

float number

returns floating-point representation of number.

max num &rest more-numbers

finds the maximum value among num and more-numbers.

min num &rest more-numbers

finds the minimum value among num and more-numbers.

make-random-state &optional (state *random-state*)

creates a fresh object of type random-state suitable for use as the value of *random-state*. If state is a random state object, the new-state is a copy of that object. If state is NIL, the new-state is a copy of the current random-state*. If state is T, the new-state is a fresh random state object that has been randomly initialized.

random range &optional (state *random-state*)

Returns a random number between 0 or 0.0 and range. If range is an integer, the result is truncated to an integer. Otherwise, a floating value is returned. Optional state can be specified to get predictable random number sequence. There is no special data type for random-state, and it is represented with an integer vector of two elements.

incf variable &optional (increment 1)

is a generalized variable. The value of variable is incremented by increment, and it is set back to variable.

decf variable &optional (decrement 1)

is a generalized variable. The value of variable is decremented by decrement, and it is set back to variable.

reduce func seq

combines all the elements in seq using the binary operator func. For an example, (reduce #’expt ’(2 3 4)) = (expt (expt 2 3) 4)=4096.

rad2deg radian

Radian value is converted to degree notation. #R does the same thing at read time. Note that the official representation of angle in EusLisp is radian and every EusLisp function that accepts angle argument requests it to be represented by radian.

deg2rad degree

Conversion from degree to radian. Also accomplished by #D reader’s dispatch macros.

Extended Numbers

ratio

:super = ** extended-number**
:slots (numerator denominator)

Describes rational numbers.

:init num denom

initializes a rational number instance with numerator num and denominator denom.

complex

:super = ** extended-number**
:slots (real imaginary)

Describes complex numbers.

:init re im

initializes a complex number instance with real part re and imaginary part im.