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
|
% This file is part of Oaklisp.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% The GNU GPL is available at http://www.gnu.org/licenses/gpl.html
% or from the Free Software Foundation, 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA
\chapter{Numbers} \label{numbers}
\index{\texttt{number}} \index{\texttt{real}} \index{\texttt{complex}}
\index{\texttt{rational}} \index{\texttt{float}} \index{\texttt{integer}}
\index{\texttt{fraction}} \index{\texttt{fixnum}} \index{\texttt{bignum}}
\begin{figure}[h]
\centering\includegraphics{numhier}
\caption{The numeric type hierarchy. Abstract types are in plain face
and instantiable ones in bold. Floating point numbers are not
implemented.} \label{fig:numhier}
\end{figure}
\section{Arithmetic}
\op{+}{\dt numbers}
\op{1+}{n}
\op{-}{n1 n2 \dt numbers}
\op{-}{n}
\op{*}{\dt numbers}
\op{/}{n1 n2}
\op{quotient}{n1 n2}
\op{modulo}{n1 n2}
\op{abs}{n1}
\op{max}{n1 n2}
\op{min}{n1 n2}
\op{expt}{n1 n2}
\section{Comparison}
\op{=}{n1 n2}
\op{{\protect\bang}=}{n1 n2}
\op{<}{n1 n2}
\op{>}{n1 n2}
\op{<=}{n1 n2}
\op{>=}{n1 n2}
\section{Predicates}
\pr{zero?}{n}
\pr{negative?}{n}
\pr{positive?}{n}
\pr{even?}{n}
\pr{odd?}{n}
\pr{factor?}{n1 n2}
\section{Rounding}
These operations should work on any subtype of \df{real}.
\op{floor}{x}
\doc{Returns the largest integer less than or equal to \emph{x}.}
\op{ceiling}{x}
\doc{Returns the smallest integer greater than or equal to \emph{x}.}
\op{truncate}{x}
\doc{Could be defined \texttt{(if (negative?\ x) (ceiling x) (floor x))}.}
\op{round}{x}
\doc{Returns nearest integer to \emph{x}. Ties are broken by rounding
to an even number.}
\section{Bitwise Logical Operations}
These operations are only defined for integers.
\op{ash-left}{i amount}
\op{ash-right}{i amount}
\op{rot-left}{i amount}
\op{rot-right}{i amount}
\op{bit-not}{i}
\op{bit-and}{i1 i2}
\op{bit-or}{i1 i2}
\op{bit-nor}{i1 i2}
\op{bit-xor}{i1 i2}
\op{bit-nand}{i1 i2}
\op{bit-andca}{i1 i2}
\op{bit-equiv}{i1 i2}
\section{Accessing Components}
\op{numerator}{rational}
\op{denominator}{rational}
\op{real-part}{number}
\op{imag-part}{number}
|