1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
\section{Arithmetic Functions}
\markright{\arabic{section}. Arithmetic}
\subsection{Arithmetic Constants}
\begin{refdesc}
\constdesc{most-positive-fixnum}{
\#x1fffffff=536,870,911}
\constdesc{most-negative-fixnum}{
-\#x20000000= -536,870,912}
\constdesc{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}$.}
\constdesc{single-float-epsilon}{
same as {\bf short-float-epsilon}, $2^{-21}$.}
\constdesc{long-float-epsilon}{
same as {\bf short-float-epsilon} since
there is no double or long float. $2^{-21}$.}
\constdesc{pi}{
$\pi$, actually 3.14159203, not 3.14159265.}
\constdesc{2pi}{
$2\times \pi$}
\constdesc{pi/2}{
$\pi/2$}
\constdesc{-pi}{
-3.14159203}
\constdesc{-2pi}{
$-2\times \pi$}
\constdesc{-pi/2}{
$\pi/2$}
\end{refdesc}
\subsection{Arithmetic Predicates}
\begin{refdesc}
\funcdesc{numberp}{object}{
T if {\em object} is number, namely integer or float.
Note that characters are also represented by numbers.}
\funcdesc{integerp}{object}{
T if {\em object} is an integer number.
A float can be converted to an integer by
{\bf round, trunc} and {\bf ceiling} functions.}
\funcdesc{floatp}{object}{
T if {\em object} is a floating-point number.
An integer can be converted to a float by the {\bf float} function.}
\funcdesc{zerop}{number}{
T if the number is integer zero or float 0.0.}
\funcdesc{plusp}{number}{
equivalent to ($>$ number 0).}
\funcdesc{minusp}{number}{
equivalent to ($<$ number 0).}
\funcdesc{oddp}{integer}{
The argument must be an integer.
T if {\em integer} is odd.}
\funcdesc{evenp}{integer}{
The argument must be an integer.
T if {\em integer} is an even number.}
\funcdesc{/=}{num1 num2 \&rest more-numbers}{
Both {\em num1}, {\em num2} and all elements of {\em more-numbers} must be numbers.
T if no two of its arguments are numerically equal, NIL otherwise.}
\funcdesc{=}{num1 num2 \&rest more-numbers}{
Both {\em n1} and {\em n2} and all elements of {\em more-numbers} must be numbers.
T if {\em n1}, {\em n2} and all elements of {\em more-numbers} are the same in value, NIL otherwise.}
\funcdesc{$>$}{num1 num2 \&rest more-numbers}{
Both {\em n1} and {\em n2} and all elements of {\em more-numbers} must be numbers.
T if {\em n1}, {\em n2} and all elements of {\em more-numbers} are in monotonically decreasing order, NIL otherwise.
For numerical comparisons with tolerance, use functions prefixed
by {\bf eps} as described in the section \ref{Geometry}.}
\funcdesc{$<$}{num1 num2 \&rest more-numbers}{
Both {\em n1} and {\em n2} and all elements of {\em more-numbers} must be numbers.
T if {\em n1}, {\em n2} and all elements of {\em more-numbers} are in monotonically increasing order, NIL otherwise.
For numerical comparisons with tolerance, use functions prefixed
by {\bf eps} as described in the section \ref{Geometry}.}
\funcdesc{$>=$}{num1 num2 \&rest more-numbers}{
Both {\em n1} and {\em n2} and all elements of {\em more-numbers} must be numbers.
T if {\em n1}, {\em n2} and all elements of {\em more-numbers} are in monotonically nonincreasing order, NIL otherwise.
For numerical comparisons with tolerance, use functions prefixed
by {\bf eps} as described in the section \ref{Geometry}.}
\funcdesc{$<=$}{num1 num2 \&rest more-numbers}{
Both {\em n1} and {\em n2} and all elements of {\em more-numbers} must be numbers.
T if {\em n1}, {\em n2} and all elements of {\em more-numbers} are in monotonically nondecreasing order, NIL otherwise.
For numerical comparisons with tolerance, use functions prefixed
by {\bf eps} as described in the section \ref{Geometry}.}
\end{refdesc}
\subsection{Integer and Bit-Wise Operations}
Following functions request arguments to be integers.
\begin{refdesc}
\funcdesc{mod}{dividend divisor}{
returns remainder when {\em dividend} is divided by {\em divisor}.
{\tt (mod 6 5)=1, (mod -6 5)=-1, (mod 6 -5)=1, (mod -6 -5)=-1}.}
\funcdesc{1-}{number}{
$number-1$ is returned.}
\funcdesc{1+}{number}{
$number+1$ is returned.}
\funcdesc{logand}{\&rest integers}{
bitwise-and of {\em integers}.}
\funcdesc{logior}{\&rest integers}{
bitwise-inclusive-or of {\em integers}.}
\funcdesc{logxor}{\&rest integers}{
bitwise-exclusive-or of {\em integers}.}
\funcdesc{logeqv}{\&rest integers}{
{\bf logeqv} is equivalent to (lognot (logxor ...)).}
\funcdesc{lognand}{\&rest integers}{
bitwise-nand of {\em integers}.}
\funcdesc{lognor}{\&rest integers}{
bitwise-nor of {\em integers}.}
\funcdesc{lognot}{integer}{
bit reverse of {\em integer}.}
\funcdesc{logtest}{integer1 integer2}{
T if (logand {\em integer1 integer2}) is not zero.}
\funcdesc{logbitp}{index integer}{
T if {\em index}th bit of {\em integer} (counted from the LSB) is 1,
otherwise NIL.}
\funcdesc{ash}{integer count}{
Arithmetic Shift Left.
If {\em count} is positive, shift direction is left,
and if {\em count} is negative,
{\em integer} is shifted to right by abs({\em count}) bits.}
\funcdesc{ldb}{target position \&optional (width 8)}{
LoaD Byte.
Byte specifier for {\bf ldb} and {\bf dpb} does not exist in EusLisp.
Use a pair of integers instead.
The field of {\em width} bits at {\em position} within {\em target}
is extracted. For example, {\tt (ldb \#x1234 4 4)} is 3.}
\funcdesc{dpb}{value target position \&optional (width 8)}{
DePosit byte.
{\em Width} bits of {\em value} is put in {\em target}
at {\em position}th bits from LSB.}
\end{refdesc}
\subsection{Generic Number Functions}
\begin{refdesc}
\funcdesc{+}{\&rest numbers}{
returns the sum of {\em numbers}.}
\funcdesc{-}{num \&rest more-numbers}{
If {\em more-numbers} are given, they are subtracted from {\em num}.
Otherwise, {\em num} is negated.}
\funcdesc{*}{\&rest numbers}{
returns the product of {\em numbers}.}
\funcdesc{/}{num \&rest more-numbers}{
{\em num} is divided by {\em more-numbers}.
If only one argument is given, 1.0 is divided by {\em 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.}
\funcdesc{abs}{number}{
returns absolute number.}
\funcdesc{round}{number}{
rounds to the nearest integer.
{\tt (round 1.5)=2, (round -1.5)=-2}.}
\funcdesc{floor}{number}{
rounds to the nearest smaller integer.
{\tt (floor 1.5)=1, (floor -1.5)=-2}.}
\funcdesc{ceiling}{number}{
rounds to the nearest larger integer.
{\tt (ceiling 1.5)=2, (ceiling -1.5)=-1}.}
\funcdesc{truncate}{number}{
rounds to the absolutely smaller and nearest integer.
{\tt (truncate 1.5)=1, (truncate -1.5)=-1}.}
\funcdesc{float}{number}{
returns floating-point representation of {\em number}.}
\funcdesc{max}{num \&rest more-numbers}{
finds the maximum value among {\em num} and {\em more-numbers}.}
\funcdesc{min}{num \&rest more-numbers}{
finds the minimum value among {\em num} and {\em more-numbers}.}
\funcdesc{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 {\em 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 {\em *random-state*}. If state is T, the new-state is a fresh random state object that has been randomly initialized.
}
\funcdesc{random}{range \&optional (state *random-state*)}{
Returns a random number between 0 or 0.0 and {\em range}.
If {\em range} is an integer,
the result is truncated to an integer.
Otherwise, a floating value is returned.
Optional {\em 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.
}
\macrodesc{incf}{variable \&optional (increment 1)}{
{\em variable} is a generalized variable.
The value of {\em variable} is incremented by {\em increment},
and it is set back to {\em variable}.}
\macrodesc{decf}{variable \&optional (decrement 1)}{
{\em variable} is a generalized variable.
The value of {\em variable} is decremented by {\em decrement},
and it is set back to {\em variable}.}
\funcdesc{reduce}{func seq}{
combines all the elements in {\em seq} using the binary operator {\em func}.
For an example, {\tt (reduce \#'expt '(2 3 4)) = (expt (expt 2 3) 4)=4096}.}
\funcdesc{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.}
\funcdesc{deg2rad}{degree}{
Conversion from degree to radian.
Also accomplished by \#D reader's dispatch macros.}
\end{refdesc}
\subsection{Trigonometric and Related Functions}
\begin{refdesc}
\funcdesc{sin}{theta}{
{\em theta} is a float representing angle by radian.
returns $sin(theta)$.}
\funcdesc{cos}{theta}{
{\em theta} is a float representing angle by radian.
returns $cos(theta)$.}
\funcdesc{tan}{theta}{
{\em theta} is a float representing angle by radian.
returns $tan(theta)$.}
\funcdesc{sinh}{x}{
hyperbolic sine, that is,
$\frac{e^{x}-e^{-x}}{2}$.}
\funcdesc{cosh}{x}{
hyperbolic cosine, that is,
$\frac{e^{x}+e^{-x}}{2}$.}
\funcdesc{tanh}{x}{
hyperbolic tangent, that is,
$\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}}$.}
\funcdesc{asin}{x}{
arc sine.}
\funcdesc{acos}{x}{
arc cosine.}
\funcdesc{atan}{y \&optional x}{
When {\bf atan} is called with one argument, its arctangent is calculated.
When called with two arguments, $atan(y/x)$ is returned.}
\funcdesc{asinh}{x}{
hyperbolic arc sine.}
\funcdesc{acosh}{x}{
hyperbolic arc cosine.}
\funcdesc{atanh}{x}{
hyperbolic arc tangent.}
\funcdesc{sqrt}{number}{
returns square root of {\em number}.}
\funcdesc{log}{number \&optional base}{
returns natural logarithm of {\em number}.
If {\em base} is provided, return the logarithm of {\em number} in the given base instead.}
\funcdesc{exp}{x}{
returns exponential, $e^{x}$.}
\funcdesc{expt}{a x}{
returns $a^{x}$.}
\end{refdesc}
\subsection{Extended Numbers}
\begin{refdesc}
\classdesc{ratio}{extended-number}{(numerator denominator)}{
Describes rational numbers.}
\methoddesc{:init}{num denom}{
initializes a rational number instance with numerator {\em num} and denominator {\em denom}.}
\classdesc{complex}{extended-number}{(real imaginary)}{
Describes complex numbers.}
\methoddesc{:init}{re im}{
initializes a complex number instance with real part {\em re} and imaginary part {\em im}.}
\end{refdesc}
\newpage
|