\doxysection{workspace/post-\/scarcity/src/arith/integer.c File Reference}
\hypertarget{integer_8c}{}\label{integer_8c}\index{workspace/post-\/scarcity/src/arith/integer.c@{workspace/post-\/scarcity/src/arith/integer.c}}
{\ttfamily \#include $<$limits.\+h$>$}\newline
{\ttfamily \#include $<$math.\+h$>$}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$inttypes.\+h$>$}\newline
{\ttfamily \#include $<$wchar.\+h$>$}\newline
{\ttfamily \#include $<$wctype.\+h$>$}\newline
{\ttfamily \#include "{}arith/integer.\+h"{}}\newline
{\ttfamily \#include "{}arith/peano.\+h"{}}\newline
{\ttfamily \#include "{}debug.\+h"{}}\newline
{\ttfamily \#include "{}memory/conspage.\+h"{}}\newline
{\ttfamily \#include "{}memory/consspaceobject.\+h"{}}\newline
{\ttfamily \#include "{}ops/equal.\+h"{}}\newline
{\ttfamily \#include "{}ops/lispops.\+h"{}}\newline
Include dependency graph for integer.\+c\+:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{integer_8c__incl}
\end{center}
\end{figure}
\doxysubsubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \mbox{\hyperlink{integer_8c_a369266c24eacffb87046522897a570d5}{\+\_\+\+GNU\+\_\+\+SOURCE}}
\item 
\#define \mbox{\hyperlink{integer_8c_a5dacb21ddf2007d5ba24c9554e7979cd}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}~24
\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_adda818b0d598bdb572e371cb6d4123b4}{acquire\+\_\+integer}} (int64\+\_\+t value, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} more)
\begin{DoxyCompactList}\small\item\em Supply small valued integers from the small integer cache, if available. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_a8b6e93c44eca207d8f88a71d90142bb9}{add\+\_\+integers}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} a, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} b)
\begin{DoxyCompactList}\small\item\em Return a pointer to an integer representing the sum of the integers pointed to by {\ttfamily a} and {\ttfamily b}. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_a05f136019ab7450d6cf4f2bb7d79f7cc}{append\+\_\+cell}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} partial, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} digit)
\begin{DoxyCompactList}\small\item\em Return a copy of this {\ttfamily partial} with this {\ttfamily digit} appended. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_ae56ef795db55d248345bb3809e6781fb}{base\+\_\+partial}} (int depth)
\item 
\+\_\+\+\_\+int128\+\_\+t \mbox{\hyperlink{integer_8c_a71d79342cc501b3e8c20b3b27ed50eb6}{cell\+\_\+value}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} c, char op, bool is\+\_\+first\+\_\+cell)
\begin{DoxyCompactList}\small\item\em Low level integer arithmetic, do not use elsewhere. \end{DoxyCompactList}\item 
bool \mbox{\hyperlink{integer_8c_a10c7e3258f3c46d3271301a7092fc52e}{equal\+\_\+integer\+\_\+integer}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} a, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} b)
\begin{DoxyCompactList}\small\item\em true if a and be are both integers whose value is the same value. \end{DoxyCompactList}\item 
\+\_\+\+\_\+int128\+\_\+t \mbox{\hyperlink{integer_8c_a6ce8da41affd570e1aff4a1f95c799ac}{int128\+\_\+to\+\_\+integer}} (\+\_\+\+\_\+int128\+\_\+t val, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} less\+\_\+significant, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} new)
\begin{DoxyCompactList}\small\item\em Overwrite the value field of the integer indicated by {\ttfamily new} with the least significant INTEGER\+\_\+\+BITS bits of {\ttfamily val}, and return the more significant bits (if any) right-\/shifted by INTEGER\+\_\+\+BITS places. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_aa9d39b6446057bc1edc01113f67db026}{integer\+\_\+to\+\_\+string}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} int\+\_\+pointer, int base)
\begin{DoxyCompactList}\small\item\em return a string representation of this integer, which may be a bignum. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_adcc5e7c527d7d2e3094ddaa3d092d429}{integer\+\_\+to\+\_\+string\+\_\+add\+\_\+digit}} (int digit, int digits, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} tail)
\begin{DoxyCompactList}\small\item\em don\textquotesingle{}t use; private to integer\+\_\+to\+\_\+string, and somewhat dodgy. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_afff1d31bb49e1be78395b0803b0b2514}{make\+\_\+integer}} (int64\+\_\+t value, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} more)
\begin{DoxyCompactList}\small\item\em Allocate an integer cell representing this {\ttfamily value} and return a \doxylink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer} to it. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_a3f0fcaa092a0c6830aa0bf7303ed1f7c}{multiply\+\_\+integers}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} a, struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} b)
\begin{DoxyCompactList}\small\item\em Return a pointer to an integer representing the product of the integers pointed to by {\ttfamily a} and {\ttfamily b}. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{integer_8c_a6888967abc1be479f518354bb802d01d}{release\+\_\+integer}} (struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} p)
\begin{DoxyCompactList}\small\item\em if the value of p is less than the size of the small integer cache (and thus it was presumably supplied from there), suppress dec\+\_\+ref. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
const char \texorpdfstring{$\ast$}{*} \mbox{\hyperlink{integer_8c_a60dbddf98757946e2eafa70b4ea3d456}{hex\+\_\+digits}} = "{}0123456789ABCDEF"{}
\begin{DoxyCompactList}\small\item\em hexadecimal digits for printing numbers. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} \mbox{\hyperlink{integer_8c_a916ca64f2ce502d3f4564fa784ce6c62}{small\+\_\+int\+\_\+cache}} \mbox{[}\mbox{\hyperlink{integer_8c_a5dacb21ddf2007d5ba24c9554e7979cd}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}\mbox{]}
\item 
bool \mbox{\hyperlink{integer_8c_a08309d32c943a89296c8bdabe88fb6fb}{small\+\_\+int\+\_\+cache\+\_\+initialised}} = false
\end{DoxyCompactItemize}


\doxysubsection{Macro Definition Documentation}
\Hypertarget{integer_8c_a369266c24eacffb87046522897a570d5}\label{integer_8c_a369266c24eacffb87046522897a570d5} 
\index{integer.c@{integer.c}!\_GNU\_SOURCE@{\_GNU\_SOURCE}}
\index{\_GNU\_SOURCE@{\_GNU\_SOURCE}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{\_GNU\_SOURCE}{\_GNU\_SOURCE}}
{\footnotesize\ttfamily \#define \+\_\+\+GNU\+\_\+\+SOURCE}



Definition at line \mbox{\hyperlink{integer_8c_source_l00010}{10}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.

\Hypertarget{integer_8c_a5dacb21ddf2007d5ba24c9554e7979cd}\label{integer_8c_a5dacb21ddf2007d5ba24c9554e7979cd} 
\index{integer.c@{integer.c}!SMALL\_INT\_LIMIT@{SMALL\_INT\_LIMIT}}
\index{SMALL\_INT\_LIMIT@{SMALL\_INT\_LIMIT}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{SMALL\_INT\_LIMIT}{SMALL\_INT\_LIMIT}}
{\footnotesize\ttfamily \#define SMALL\+\_\+\+INT\+\_\+\+LIMIT~24}



Definition at line \mbox{\hyperlink{integer_8c_source_l00050}{50}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



\doxysubsection{Function Documentation}
\Hypertarget{integer_8c_adda818b0d598bdb572e371cb6d4123b4}\label{integer_8c_adda818b0d598bdb572e371cb6d4123b4} 
\index{integer.c@{integer.c}!acquire\_integer@{acquire\_integer}}
\index{acquire\_integer@{acquire\_integer}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{acquire\_integer()}{acquire\_integer()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} acquire\+\_\+integer (\begin{DoxyParamCaption}\item[{int64\+\_\+t}]{value,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{more }\end{DoxyParamCaption})}



Supply small valued integers from the small integer cache, if available. 

The pattern here is intended to be that, at least within this file, instead of calling make\+\_\+integer when an integer is required and dec\+\_\+ref when it\textquotesingle{}s no longer required, we call acquire\+\_\+integer and release\+\_\+integer respectively, in order to reduce allocation churn.

In the initial implementation, acquire\+\_\+integer supplies the integer from the small integer cache if available, else calls make\+\_\+integer. Later, more sophisticated caching of integers which are currently in play may be enabled.


\begin{DoxyParams}{Parameters}
{\em value} & the value of the integer desired. \\
\hline
{\em more} & if this value is a bignum, the rest (less significant bits) of the value. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
struct \doxylink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer} a pointer to the integer acquired. 
\end{DoxyReturn}


Definition at line \mbox{\hyperlink{integer_8c_source_l00129}{129}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{debug_8h_source_l00021}{DEBUG\+\_\+\+ALLOC}}, \mbox{\hyperlink{debug_8c_source_l00041}{debug\+\_\+print()}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{integer_8c_source_l00089}{make\+\_\+integer()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}, \mbox{\hyperlink{integer_8c_source_l00052}{small\+\_\+int\+\_\+cache}}, \mbox{\hyperlink{integer_8c_source_l00051}{small\+\_\+int\+\_\+cache\+\_\+initialised}}, and \mbox{\hyperlink{integer_8c_source_l00050}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}.



Referenced by \mbox{\hyperlink{ratio_8c_source_l00137}{add\+\_\+integer\+\_\+ratio()}}, \mbox{\hyperlink{integer_8c_source_l00224}{add\+\_\+integers()}}, \mbox{\hyperlink{integer_8c_source_l00288}{base\+\_\+partial()}}, \mbox{\hyperlink{ratio_8c_source_l00254}{multiply\+\_\+integer\+\_\+ratio()}}, \mbox{\hyperlink{integer_8c_source_l00343}{multiply\+\_\+integers()}}, \mbox{\hyperlink{ratio_8c_source_l00203}{multiply\+\_\+ratio\+\_\+ratio()}}, \mbox{\hyperlink{read_8c_source_l00288}{read\+\_\+number()}}, and \mbox{\hyperlink{ratio_8c_source_l00048}{simplify\+\_\+ratio()}}.

\Hypertarget{integer_8c_a8b6e93c44eca207d8f88a71d90142bb9}\label{integer_8c_a8b6e93c44eca207d8f88a71d90142bb9} 
\index{integer.c@{integer.c}!add\_integers@{add\_integers}}
\index{add\_integers@{add\_integers}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{add\_integers()}{add\_integers()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} add\+\_\+integers (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{a,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{b }\end{DoxyParamCaption})}



Return a pointer to an integer representing the sum of the integers pointed to by {\ttfamily a} and {\ttfamily b}. 

If either isn\textquotesingle{}t an integer, will return nil. 

Definition at line \mbox{\hyperlink{integer_8c_source_l00224}{224}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}, \mbox{\hyperlink{integer_8c_source_l00065}{cell\+\_\+value()}}, \mbox{\hyperlink{debug_8h_source_l00028}{DEBUG\+\_\+\+ARITH}}, \mbox{\hyperlink{debug_8c_source_l00136}{debug\+\_\+dump\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00041}{debug\+\_\+print()}}, \mbox{\hyperlink{debug_8c_source_l00058}{debug\+\_\+print\+\_\+128bit()}}, \mbox{\hyperlink{debug_8c_source_l00119}{debug\+\_\+print\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00085}{debug\+\_\+println()}}, \mbox{\hyperlink{integer_8c_source_l00193}{int128\+\_\+to\+\_\+integer()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{integer_8c_source_l00089}{make\+\_\+integer()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}, and \mbox{\hyperlink{integer_8c_source_l00050}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}.



Referenced by \mbox{\hyperlink{peano_8c_source_l00217}{add\+\_\+2()}}, \mbox{\hyperlink{ratio_8c_source_l00093}{add\+\_\+ratio\+\_\+ratio()}}, \mbox{\hyperlink{integer_8c_source_l00343}{multiply\+\_\+integers()}}, \mbox{\hyperlink{read_8c_source_l00288}{read\+\_\+number()}}, and \mbox{\hyperlink{peano_8c_source_l00544}{subtract\+\_\+2()}}.

\Hypertarget{integer_8c_a05f136019ab7450d6cf4f2bb7d79f7cc}\label{integer_8c_a05f136019ab7450d6cf4f2bb7d79f7cc} 
\index{integer.c@{integer.c}!append\_cell@{append\_cell}}
\index{append\_cell@{append\_cell}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{append\_cell()}{append\_cell()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} append\+\_\+cell (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{partial,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{digit }\end{DoxyParamCaption})}



Return a copy of this {\ttfamily partial} with this {\ttfamily digit} appended. 


\begin{DoxyParams}{Parameters}
{\em partial} & the more significant bits of a possible bignum. \\
\hline
{\em digit} & the less significant bits of that possible bignum. NOTE\+: the name {\ttfamily digit} is technically correct but possibly misleading, because the numbering system here is base INT\+\_\+\+CELL\+\_\+\+BASE, currently x0fffffffffffffffL \\
\hline
\end{DoxyParams}


Definition at line \mbox{\hyperlink{integer_8c_source_l00308}{308}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{integer_8c_source_l00089}{make\+\_\+integer()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{cons\+\_\+space\+\_\+object\+::payload}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00343}{multiply\+\_\+integers()}}.

\Hypertarget{integer_8c_ae56ef795db55d248345bb3809e6781fb}\label{integer_8c_ae56ef795db55d248345bb3809e6781fb} 
\index{integer.c@{integer.c}!base\_partial@{base\_partial}}
\index{base\_partial@{base\_partial}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{base\_partial()}{base\_partial()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} base\+\_\+partial (\begin{DoxyParamCaption}\item[{int}]{depth }\end{DoxyParamCaption})}



Definition at line \mbox{\hyperlink{integer_8c_source_l00288}{288}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}, \mbox{\hyperlink{debug_8h_source_l00028}{DEBUG\+\_\+\+ARITH}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00343}{multiply\+\_\+integers()}}.

\Hypertarget{integer_8c_a71d79342cc501b3e8c20b3b27ed50eb6}\label{integer_8c_a71d79342cc501b3e8c20b3b27ed50eb6} 
\index{integer.c@{integer.c}!cell\_value@{cell\_value}}
\index{cell\_value@{cell\_value}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{cell\_value()}{cell\_value()}}
{\footnotesize\ttfamily \+\_\+\+\_\+int128\+\_\+t cell\+\_\+value (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{c,  }\item[{char}]{op,  }\item[{bool}]{is\+\_\+first\+\_\+cell }\end{DoxyParamCaption})}



Low level integer arithmetic, do not use elsewhere. 


\begin{DoxyParams}{Parameters}
{\em c} & a pointer to a cell, assumed to be an integer cell; \\
\hline
{\em op} & a character representing the operation\+: expected to be either \textquotesingle{}+\textquotesingle{} or \textquotesingle{}\texorpdfstring{$\ast$}{*}\textquotesingle{}; behaviour with other values is undefined. \\
\hline
{\em is\+\_\+first\+\_\+cell} & true if this is the first cell in a bignum chain, else false. \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\doxylink{integer_8c_a3f0fcaa092a0c6830aa0bf7303ed1f7c}{multiply\+\_\+integers} 

\doxylink{integer_8c_a8b6e93c44eca207d8f88a71d90142bb9}{add\+\_\+integers} 
\end{DoxySeeAlso}


Definition at line \mbox{\hyperlink{integer_8c_source_l00065}{65}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{debug_8h_source_l00028}{DEBUG\+\_\+\+ARITH}}, \mbox{\hyperlink{debug_8c_source_l00058}{debug\+\_\+print\+\_\+128bit()}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{debug_8c_source_l00085}{debug\+\_\+println()}}, \mbox{\hyperlink{peano_8h_source_l00026}{INT\+\_\+\+CELL\+\_\+\+BASE}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00224}{add\+\_\+integers()}}.

\Hypertarget{integer_8c_a10c7e3258f3c46d3271301a7092fc52e}\label{integer_8c_a10c7e3258f3c46d3271301a7092fc52e} 
\index{integer.c@{integer.c}!equal\_integer\_integer@{equal\_integer\_integer}}
\index{equal\_integer\_integer@{equal\_integer\_integer}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{equal\_integer\_integer()}{equal\_integer\_integer()}}
{\footnotesize\ttfamily bool equal\+\_\+integer\+\_\+integer (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{a,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{b }\end{DoxyParamCaption})}



true if a and be are both integers whose value is the same value. 



Definition at line \mbox{\hyperlink{integer_8c_source_l00511}{511}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{cons\+\_\+space\+\_\+object\+::payload}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}.



Referenced by \mbox{\hyperlink{equal_8c_source_l00120}{equal\+\_\+integer\+\_\+number()}}, and \mbox{\hyperlink{ratio_8c_source_l00357}{equal\+\_\+ratio\+\_\+ratio()}}.

\Hypertarget{integer_8c_a6ce8da41affd570e1aff4a1f95c799ac}\label{integer_8c_a6ce8da41affd570e1aff4a1f95c799ac} 
\index{integer.c@{integer.c}!int128\_to\_integer@{int128\_to\_integer}}
\index{int128\_to\_integer@{int128\_to\_integer}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{int128\_to\_integer()}{int128\_to\_integer()}}
{\footnotesize\ttfamily \+\_\+\+\_\+int128\+\_\+t int128\+\_\+to\+\_\+integer (\begin{DoxyParamCaption}\item[{\+\_\+\+\_\+int128\+\_\+t}]{val,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{less\+\_\+significant,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{new }\end{DoxyParamCaption})}



Overwrite the value field of the integer indicated by {\ttfamily new} with the least significant INTEGER\+\_\+\+BITS bits of {\ttfamily val}, and return the more significant bits (if any) right-\/shifted by INTEGER\+\_\+\+BITS places. 

Destructive, primitive, DO NOT USE in any context except primitive operations on integers. The value passed as {\ttfamily new} MUST be constructed with {\ttfamily make\+\_\+integer}, NOT acquired with {\ttfamily acquire\+\_\+integer}.


\begin{DoxyParams}{Parameters}
{\em val} & the value to represent; \\
\hline
{\em less\+\_\+significant} & the less significant words of this bignum, if any, else NIL; \\
\hline
{\em new} & a newly created integer, which will be destructively changed. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
carry, if any, else 0. 
\end{DoxyReturn}


Definition at line \mbox{\hyperlink{integer_8c_source_l00193}{193}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{debug_8h_source_l00028}{DEBUG\+\_\+\+ARITH}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{consspaceobject_8c_source_l00062}{inc\+\_\+ref()}}, \mbox{\hyperlink{peano_8h_source_l00026}{INT\+\_\+\+CELL\+\_\+\+BASE}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{peano_8h_source_l00025}{MAX\+\_\+\+INTEGER}}, \mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{cons\+\_\+space\+\_\+object\+::payload}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00224}{add\+\_\+integers()}}.

\Hypertarget{integer_8c_aa9d39b6446057bc1edc01113f67db026}\label{integer_8c_aa9d39b6446057bc1edc01113f67db026} 
\index{integer.c@{integer.c}!integer\_to\_string@{integer\_to\_string}}
\index{integer\_to\_string@{integer\_to\_string}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{integer\_to\_string()}{integer\_to\_string()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} integer\+\_\+to\+\_\+string (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{int\+\_\+pointer,  }\item[{int}]{base }\end{DoxyParamCaption})}



return a string representation of this integer, which may be a bignum. 

The general principle of printing a bignum is that you print the least significant digit in whatever base you\textquotesingle{}re dealing with, divide through by the base, print the next, and carry on until you\textquotesingle{}ve none left. Obviously, that means you print from right to left. Given that we build strings from right to left, \textquotesingle{}printing\textquotesingle{} an integer to a lisp string would seem reasonably easy. The problem is when you jump from one integer object to the next. 64 bit integers don\textquotesingle{}t align with decimal numbers, so when we get to the last digit from one integer cell, we have potentially to be looking to the next. H\textquotesingle{}mmmm.


\begin{DoxyParams}{Parameters}
{\em int\+\_\+pointer} & \doxylink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer} to the integer to print, \\
\hline
{\em base} & the base to print it in. \\
\hline
\end{DoxyParams}


Definition at line \mbox{\hyperlink{integer_8c_source_l00454}{454}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{consspaceobject_8c_source_l00454}{c\+\_\+string\+\_\+to\+\_\+lisp\+\_\+string()}}, \mbox{\hyperlink{debug_8h_source_l00056}{DEBUG\+\_\+\+IO}}, \mbox{\hyperlink{debug_8c_source_l00041}{debug\+\_\+print()}}, \mbox{\hyperlink{debug_8c_source_l00058}{debug\+\_\+print\+\_\+128bit()}}, \mbox{\hyperlink{debug_8c_source_l00119}{debug\+\_\+print\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{debug_8c_source_l00085}{debug\+\_\+println()}}, \mbox{\hyperlink{integer_8c_source_l00033}{hex\+\_\+digits}}, \mbox{\hyperlink{peano_8h_source_l00026}{INT\+\_\+\+CELL\+\_\+\+BASE}}, \mbox{\hyperlink{integer_8c_source_l00420}{integer\+\_\+to\+\_\+string\+\_\+add\+\_\+digit()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{peano_8c_source_l00070}{is\+\_\+negative()}}, \mbox{\hyperlink{consspaceobject_8c_source_l00338}{make\+\_\+string()}}, \mbox{\hyperlink{peano_8h_source_l00025}{MAX\+\_\+\+INTEGER}}, \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00419}{cons\+\_\+pointer\+::offset}}, \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00343}{stringp}}.



Referenced by \mbox{\hyperlink{print_8c_source_l00151}{print()}}.

\Hypertarget{integer_8c_adcc5e7c527d7d2e3094ddaa3d092d429}\label{integer_8c_adcc5e7c527d7d2e3094ddaa3d092d429} 
\index{integer.c@{integer.c}!integer\_to\_string\_add\_digit@{integer\_to\_string\_add\_digit}}
\index{integer\_to\_string\_add\_digit@{integer\_to\_string\_add\_digit}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{integer\_to\_string\_add\_digit()}{integer\_to\_string\_add\_digit()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} integer\+\_\+to\+\_\+string\+\_\+add\+\_\+digit (\begin{DoxyParamCaption}\item[{int}]{digit,  }\item[{int}]{digits,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{tail }\end{DoxyParamCaption})}



don\textquotesingle{}t use; private to integer\+\_\+to\+\_\+string, and somewhat dodgy. 



Definition at line \mbox{\hyperlink{integer_8c_source_l00420}{420}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{debug_8h_source_l00056}{DEBUG\+\_\+\+IO}}, \mbox{\hyperlink{debug_8c_source_l00119}{debug\+\_\+print\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{debug_8c_source_l00085}{debug\+\_\+println()}}, \mbox{\hyperlink{integer_8c_source_l00033}{hex\+\_\+digits}}, and \mbox{\hyperlink{consspaceobject_8c_source_l00338}{make\+\_\+string()}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00454}{integer\+\_\+to\+\_\+string()}}.

\Hypertarget{integer_8c_afff1d31bb49e1be78395b0803b0b2514}\label{integer_8c_afff1d31bb49e1be78395b0803b0b2514} 
\index{integer.c@{integer.c}!make\_integer@{make\_integer}}
\index{make\_integer@{make\_integer}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{make\_integer()}{make\_integer()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} make\+\_\+integer (\begin{DoxyParamCaption}\item[{int64\+\_\+t}]{value,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{more }\end{DoxyParamCaption})}



Allocate an integer cell representing this {\ttfamily value} and return a \doxylink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer} to it. 


\begin{DoxyParams}{Parameters}
{\em value} & an integer value; \\
\hline
{\em more} & {\ttfamily NIL}, or a pointer to the more significant cell(s) of this number. {\itshape NOTE} that if {\ttfamily more} is not {\ttfamily NIL}, {\ttfamily value} {\itshape must not} exceed {\ttfamily MAX\+\_\+\+INTEGER}. \\
\hline
\end{DoxyParams}


Definition at line \mbox{\hyperlink{integer_8c_source_l00089}{89}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{conspage_8c_source_l00222}{allocate\+\_\+cell()}}, \mbox{\hyperlink{debug_8h_source_l00021}{DEBUG\+\_\+\+ALLOC}}, \mbox{\hyperlink{debug_8c_source_l00136}{debug\+\_\+dump\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00041}{debug\+\_\+print()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00090}{INTEGERTV}}, \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{cons\+\_\+space\+\_\+object\+::payload}}, and \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}.



Referenced by \mbox{\hyperlink{peano_8c_source_l00089}{absolute()}}, \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}, \mbox{\hyperlink{integer_8c_source_l00224}{add\+\_\+integers()}}, \mbox{\hyperlink{io_8c_source_l00268}{add\+\_\+meta\+\_\+integer()}}, \mbox{\hyperlink{integer_8c_source_l00308}{append\+\_\+cell()}}, \mbox{\hyperlink{peano_8c_source_l00314}{lisp\+\_\+add()}}, \mbox{\hyperlink{peano_8c_source_l00655}{lisp\+\_\+divide()}}, \mbox{\hyperlink{hashmap_8c_source_l00025}{lisp\+\_\+get\+\_\+hash()}}, \mbox{\hyperlink{lispops_8c_source_l00818}{lisp\+\_\+length()}}, \mbox{\hyperlink{peano_8c_source_l00453}{lisp\+\_\+multiply()}}, \mbox{\hyperlink{peano_8c_source_l00489}{negative()}}, and \mbox{\hyperlink{peano_8c_source_l00544}{subtract\+\_\+2()}}.

\Hypertarget{integer_8c_a3f0fcaa092a0c6830aa0bf7303ed1f7c}\label{integer_8c_a3f0fcaa092a0c6830aa0bf7303ed1f7c} 
\index{integer.c@{integer.c}!multiply\_integers@{multiply\_integers}}
\index{multiply\_integers@{multiply\_integers}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{multiply\_integers()}{multiply\_integers()}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} multiply\+\_\+integers (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{a,  }\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{b }\end{DoxyParamCaption})}



Return a pointer to an integer representing the product of the integers pointed to by {\ttfamily a} and {\ttfamily b}. 

If either isn\textquotesingle{}t an integer, will return nil.

Yes, this is one of Muhammad ibn Musa al-\/\+Khwarizmi\textquotesingle{}s original recipes, so you\textquotesingle{}d think it would be easy; the reason that each step is documented is because I did not find it so.


\begin{DoxyParams}{Parameters}
{\em a} & an integer; \\
\hline
{\em b} & an integer. \\
\hline
\end{DoxyParams}


Definition at line \mbox{\hyperlink{integer_8c_source_l00343}{343}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}, \mbox{\hyperlink{integer_8c_source_l00224}{add\+\_\+integers()}}, \mbox{\hyperlink{integer_8c_source_l00308}{append\+\_\+cell()}}, \mbox{\hyperlink{integer_8c_source_l00288}{base\+\_\+partial()}}, \mbox{\hyperlink{debug_8h_source_l00028}{DEBUG\+\_\+\+ARITH}}, \mbox{\hyperlink{debug_8c_source_l00041}{debug\+\_\+print()}}, \mbox{\hyperlink{debug_8c_source_l00119}{debug\+\_\+print\+\_\+object()}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{debug_8c_source_l00085}{debug\+\_\+println()}}, \mbox{\hyperlink{peano_8h_source_l00032}{INTEGER\+\_\+\+BIT\+\_\+\+SHIFT}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{peano_8c_source_l00070}{is\+\_\+negative()}}, \mbox{\hyperlink{peano_8h_source_l00025}{MAX\+\_\+\+INTEGER}}, \mbox{\hyperlink{consspaceobject_8h_source_l00277}{NIL}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}, \mbox{\hyperlink{integer_8h_source_l00017}{replace\+\_\+integer\+\_\+i}}, and \mbox{\hyperlink{integer_8h_source_l00018}{replace\+\_\+integer\+\_\+p}}.



Referenced by \mbox{\hyperlink{ratio_8c_source_l00093}{add\+\_\+ratio\+\_\+ratio()}}, \mbox{\hyperlink{peano_8c_source_l00349}{multiply\+\_\+2()}}, and \mbox{\hyperlink{read_8c_source_l00288}{read\+\_\+number()}}.

\Hypertarget{integer_8c_a6888967abc1be479f518354bb802d01d}\label{integer_8c_a6888967abc1be479f518354bb802d01d} 
\index{integer.c@{integer.c}!release\_integer@{release\_integer}}
\index{release\_integer@{release\_integer}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{release\_integer()}{release\_integer()}}
{\footnotesize\ttfamily void release\+\_\+integer (\begin{DoxyParamCaption}\item[{struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}}}]{p }\end{DoxyParamCaption})}



if the value of p is less than the size of the small integer cache (and thus it was presumably supplied from there), suppress dec\+\_\+ref. 

{\bfseries{NOTE THAT}} at this stage it\textquotesingle{}s still safe to dec\+\_\+ref an arbitrary integer, because those in the cache are locked and can\textquotesingle{}t be dec\+\_\+refed.


\begin{DoxyParams}{Parameters}
{\em p} & a pointer, expected to be to an integer. \\
\hline
\end{DoxyParams}


Definition at line \mbox{\hyperlink{integer_8c_source_l00163}{163}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



References \mbox{\hyperlink{debug_8h_source_l00021}{DEBUG\+\_\+\+ALLOC}}, \mbox{\hyperlink{debug_8c_source_l00101}{debug\+\_\+printf()}}, \mbox{\hyperlink{consspaceobject_8c_source_l00080}{dec\+\_\+ref()}}, \mbox{\hyperlink{equal_8c_source_l00024}{eq()}}, \mbox{\hyperlink{consspaceobject_8h_source_l00353}{integerp}}, \mbox{\hyperlink{consspaceobject_8h_source_l00303}{nilp}}, \mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{cons\+\_\+space\+\_\+object\+::payload}}, \mbox{\hyperlink{consspaceobject_8h_source_l00297}{pointer2cell}}, \mbox{\hyperlink{integer_8c_source_l00052}{small\+\_\+int\+\_\+cache}}, and \mbox{\hyperlink{integer_8c_source_l00050}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}.



Referenced by \mbox{\hyperlink{ratio_8c_source_l00137}{add\+\_\+integer\+\_\+ratio()}}, \mbox{\hyperlink{ratio_8c_source_l00254}{multiply\+\_\+integer\+\_\+ratio()}}, and \mbox{\hyperlink{ratio_8c_source_l00203}{multiply\+\_\+ratio\+\_\+ratio()}}.



\doxysubsection{Variable Documentation}
\Hypertarget{integer_8c_a60dbddf98757946e2eafa70b4ea3d456}\label{integer_8c_a60dbddf98757946e2eafa70b4ea3d456} 
\index{integer.c@{integer.c}!hex\_digits@{hex\_digits}}
\index{hex\_digits@{hex\_digits}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{hex\_digits}{hex\_digits}}
{\footnotesize\ttfamily const char\texorpdfstring{$\ast$}{*} hex\+\_\+digits = "{}0123456789ABCDEF"{}}



hexadecimal digits for printing numbers. 



Definition at line \mbox{\hyperlink{integer_8c_source_l00033}{33}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00454}{integer\+\_\+to\+\_\+string()}}, and \mbox{\hyperlink{integer_8c_source_l00420}{integer\+\_\+to\+\_\+string\+\_\+add\+\_\+digit()}}.

\Hypertarget{integer_8c_a916ca64f2ce502d3f4564fa784ce6c62}\label{integer_8c_a916ca64f2ce502d3f4564fa784ce6c62} 
\index{integer.c@{integer.c}!small\_int\_cache@{small\_int\_cache}}
\index{small\_int\_cache@{small\_int\_cache}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{small\_int\_cache}{small\_int\_cache}}
{\footnotesize\ttfamily struct \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\+\_\+pointer}} small\+\_\+int\+\_\+cache\mbox{[}\mbox{\hyperlink{integer_8c_a5dacb21ddf2007d5ba24c9554e7979cd}{SMALL\+\_\+\+INT\+\_\+\+LIMIT}}\mbox{]}}



Definition at line \mbox{\hyperlink{integer_8c_source_l00052}{52}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}, and \mbox{\hyperlink{integer_8c_source_l00163}{release\+\_\+integer()}}.

\Hypertarget{integer_8c_a08309d32c943a89296c8bdabe88fb6fb}\label{integer_8c_a08309d32c943a89296c8bdabe88fb6fb} 
\index{integer.c@{integer.c}!small\_int\_cache\_initialised@{small\_int\_cache\_initialised}}
\index{small\_int\_cache\_initialised@{small\_int\_cache\_initialised}!integer.c@{integer.c}}
\doxysubsubsection{\texorpdfstring{small\_int\_cache\_initialised}{small\_int\_cache\_initialised}}
{\footnotesize\ttfamily bool small\+\_\+int\+\_\+cache\+\_\+initialised = false}



Definition at line \mbox{\hyperlink{integer_8c_source_l00051}{51}} of file \mbox{\hyperlink{integer_8c_source}{integer.\+c}}.



Referenced by \mbox{\hyperlink{integer_8c_source_l00129}{acquire\+\_\+integer()}}.

