%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%  bigint.tex        LiDIA documentation
%%
%%  This file contains the documentation of the class bigint
%%  
%%  Copyright (c) 1995 by the LiDIA Group
%%
%%  Authors: Thomas Papanikolaou
%%  

\begin{lidia_man}
\markright{\BF{bigint}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NAME
\BF{bigint}   \DOTFILL     multiprecision    integer   arithmetic
\label{bigint_class}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ABSTRACT
\BF{bigint}  is  a  class  that provides a multiprecision integer
arithmetic.  A  variable of type \BF{bigint} can hold  an integer
with  arbitrarily  many  digits.  Since  all operators  which are
available  for machine  integers (e.g.~int) are  also defined for
the  type  \BF{bigint}  you  can  regard  a   variable   of  type
\BF{bigint} as an int variable without length restriction.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DESCRIPTION
\label{bigint_description}\BF{bigint} is an interface that calls 
functions  provided  by  the  kernel. Thus the representation of 
variables depends on the data types used in that level. There is 
a fixed base \MATH{B>0}, which we call \BF{bigint base} and which 
determines the  representation of  each  integer  \MATH{n} by the 
array \MATH{[m_0, m_1, \LDOTS, m_{l - 1}]},   with   \MATH{l = 
\LFLOOR \log _B (n) \RFLOOR + 1}, \MATH{m_i \GE 0} for \MATH{0 \LE 
i \LT l} and

\centerline{\MATH{n = \mbox{sign}(n) \CDOT \SUM{i = 0}{l - 1}
{m_i \CDOT B^i}}}

The coefficients \MATH{m_i} are called \BF{base digits}, \MATH{l}
is  called  the  \BF{length}  of  the  representation   and   the
\BF{mantissa} is the array \MATH{[m_0, m_1, \LDOTS, m_{l-1}]}. We
assume   that    the   kernel   supports   such   a  vector based
representation  for  long integers, i.e., it  defines such a base
\MATH{B}, the functions \BF{sign} for the calculation of the sign
of a long integer, \BF{length} for the  length of a long integer,
and pointers to the mantissas of represented integers. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\CONS
\fcode{ct}{bigint}{}
{
Initializes with 0.}


\fcode{ct}{bigint}{int}
{
Initializes with an integer.}


\fcode{ct}{bigint}{long}
{
Initializes with long.}


\fcode{ct}{bigint}{unsigned long}
{
Initializes with unsigned long.}


\fcode{ct}{bigint}{const bigint \&}
{
Initializes with a bigint. }


\fcode{dt}{\SIM bigint}{}
{
Deletes the bigint object.}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\TYPE

Before  assigning  a  \BF{bigint}  variable  to  a  machine  type
variable  (e.g.~int)  it is often useful to perform  a test which
checks  whether the assignment can be done without overflow.  The
following  functions  return \TRUE\ if an assignment is possible,
\FALSE\ otherwise.


\fcode{bool}{is\_char}{const bigint \&}{}
\fcode{bool}{is\_uchar}{const bigint \&}{}
\fcode{bool}{is\_short}{const bigint \&}{}
\fcode{bool}{is\_ushort}{const bigint \&}{}
\fcode{bool}{is\_int}{const bigint \&}{}
\fcode{bool}{is\_uint}{const bigint \&}{}
\fcode{bool}{is\_long}{const bigint \&}{}
\fcode{bool}{is\_ulong}{const bigint \&}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ASGN

Let  \MATH{a}  be of type \BF{bigint}.  The  operator  \TT{=}  is
overloaded.   For  efficiency reasons,  the  following  functions
are also implemented:


\fcode{void}{a.assign\_zero}{}
{
\MATH{a = 0}.}


\fcode{void}{a.assign\_one}{}
{
\MATH{a = 1}.}


\fcode{void}{a.assign}{int i}
{
\MATH{a = i}.}


\fcode{void}{a.assign}{long ui}
{
\MATH{a = ui}.}


\fcode{void}{a.assign}{unsigned long ui}
{
\MATH{a = ui}.}

\fcode{void}{a.assign}{double d}
{
\MATH{a = d}.}

\fcode{void}{a.assign}{const bigint \& I}
{
\MATH{a = I}.}


\cfcode{bool}{a.intify}{int \& i}
{
checks whether \MATH{a} can be converted into an int.
If this can successfully be done, the function will
assign \MATH{i = a} and return \FALSE; otherwise, it returns
\TRUE\ and \MATH{i} will be left unchanged.}


\cfcode{bool}{a.longify}{long \& i}
{
checks whether \MATH{a} can be converted into a long.
If this can successfully be done, the function will assign
\MATH{i = a} and return \FALSE; otherwise, it returns
\TRUE\ and \MATH{i} will be left unchanged.}


\fcode{double}{dbl}{const bigint \& a}
{
returns \MATH{x = (double)a}. If \MATH{a} is too large to be
stored in a double variable, \MATH{x} will be the special
value \BF{infinity} which is used in C++ to denote a value
too large to be stored in a double variable.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ARTH

The following operators are overloaded and can be used in exactly
the  same  way  as  for  machine  types  in  C++ (e.g.~int):

\begin{center}
\TT{(unary) -, ++, --}\\
\TT{(binary) +, -, *, /, \%, <<, >>, \SIM, \&, |, \^{}}\\
\TT{(binary with assignment) +=,  -=,  *=,  /=, \%=, <<=, >>=,}\\ 
\TT{\&=, |= }
\end{center}

Let  \MATH{a}  be  of  type \BF{bigint}. To  avoid copying, these
operations can also be performed by the following functions:


\fcode{void}{add}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a + b}.}


\fcode{void}{add}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a + i}.}


\fcode{void}{subtract}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a - b}.}


\fcode{void}{subtract}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a - i}.}


\fcode{void}{multiply}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a * b}.}


\fcode{void}{multiply}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a * i}.}


\fcode{void}{divide}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a / b}, if \MATH{b \NEQ 0}. Otherwise the \TT{lidia\_error\_handler}
will be invoked.}


\fcode{void}{divide}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a / i}, if \MATH{i \NEQ 0}. Otherwise the \TT{lidia\_error\_handler}
will be invoked.}


\fcode{void}{remainder}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
computes \MATH{c}, with \MATH{c \EQUIV a \MOD b}, \MATH{|c| < |b|}
and \TT{sign(c)=sign(a)}.}


\fcode{void}{remainder}{long \& c\k const bigint \& a\k long i}
{
computes \MATH{c}, with \MATH{c \EQUIV a \MOD i},
\MATH{|c| < |i|} and \TT{sign(c)=sign(a)}.}


\fcode{long}{remainder}{const bigint \& a\k long i}
{
returns a value \MATH{c}, with \MATH{c \EQUIV a \MOD i},
\MATH{|c| < |i|} and \TT{sign(c)=sign(a)}.}


\fcode{void}{div\_rem}{bigint \& q\k  bigint \& r\k const bigint \& a\k const bigint \& b}
{
computes \MATH{q} and \MATH{r} such that \MATH{a = b * q + r},
\MATH{|r| < |b|} and \TT{sign(r) = sign(a)}.}


\fcode{void}{div\_rem}{bigint \& q\k long \& r\k     const bigint \& a\k long i}
{
computes \MATH{q} and \MATH{r} such that \MATH{a = i * q + r},
\MATH{|r| < |i|} and \TT{sign(r) = sign(a)}.}


\fcode{void}{a.multiply\_by\_2}{}
{
\MATH{a = a * 2}.}


\fcode{void}{a.divide\_by\_2}{}
{
\MATH{a = sign(a) \CDOT \LFLOOR \FRAC{\ABS{a}}{2} \RFLOOR}.}


\fcode{void}{a.negate}{}
{
\MATH{a = -a}.}


\fcode{void}{negate}{bigint \& b\k const bigint \& a}
{
\MATH{b = -a}.}


\fcode{void}{inc}{bigint \& c}
{
\MATH{c = c + 1}.}


\fcode{void}{dec}{bigint \& c}
{
\MATH{c = c - 1}.}


\fcode{void}{square}{bigint \& a\k const bigint \& b}
{
\MATH{a = b^2}.}


\fcode{void}{sqrt}{bigint \& a\k const bigint \& b}
{
\MATH{a} is set to the positive value of \MATH{\LFLOOR \SQRT{b} \RFLOOR}
if \MATH{b \GEQ 0}. Otherwise the \TT{lidia\_error\_handler} will be invoked.}


\fcode{void}{power}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a^b}. For negative exponents \MATH{b}, the result of
this computation will be 0 if \MATH{a > 1}, \MATH{\PM 1}
respectively if \MATH{a= \PM 1} and 0 if \MATH{a=0}.}


\fcode{void}{power}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a^i}. For negative exponents \MATH{i}, the result
of this computation will be 0 if \MATH{a > 1}, \MATH{\PM 1}
respectively if \MATH{a= \PM 1} and 0 if \MATH{a=0}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\SHFT

\fcode{void}{shift\_left}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a << i}, if \MATH{i \GEQ 0}. Otherwise the \TT{lidia\_error\_handler}
will be invoked.}


\fcode{void}{shift\_right}{bigint \& c\k const bigint \& a\k long i}
{
\MATH{c = a >> i}, if \MATH{i \GEQ 0}. Otherwise the \TT{lidia\_error\_handler}
will be invoked.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\BIT

\fcode{void}{and}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a \WEDGE b}.}


\fcode{void}{or}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a \VEE b}.}


\fcode{void}{xor}{bigint \& c\k const bigint \& a\k const bigint \& b}
{
\MATH{c = a \MID b}.}


\fcode{void}{not}{bigint \& c\k const bigint \& a}
{
\MATH{c = \NEG a}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\COMP

The  binary operators \TT{==}, \TT{!=}, \TT{>=}, \TT{<=}, \TT{>},
\TT{<}  and  the unary operator \TT{!} (comparison with zero) are
overloaded and can be used in exactly the same way as for machine
types  in  C  (e.g.~int).  Let  \MATH{a}  be  an instance of type
\BF{bigint}.


\cfcode{bool}{a.is\_zero}{}
{
returns \TRUE\ if \MATH{a = 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_one}{}
{
returns \TRUE\ if \MATH{a = 1}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_gt\_zero}{}
{
returns \TRUE\ if \MATH{a > 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_ge\_zero}{}
{
returns \TRUE\ if \MATH{a \GE 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_lt\_zero}{}
{
returns \TRUE\ if \MATH{a < 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_le\_zero}{}
{
returns \TRUE\ if \MATH{a \LE 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_positive}{}
{
returns \TRUE\ if \MATH{a > 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_negative}{}
{
returns \TRUE\ if \MATH{a < 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_even}{}
{
returns \TRUE\ if \MATH{a \MOD 2 = 0}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_odd}{}
{
returns \TRUE\ if \MATH{a \MOD 2 = 1}, \FALSE\ otherwise.}


\cfcode{int}{a.abs\_compare}{const bigint \& b}
{
returns \TT{sign((|a|-|b|)}.}


\cfcode{int}{a.compare}{const bigint \& b}
{
returns \TT{sign(a-b)}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\BASIC

Let \MATH{a} be of type \BF{bigint}.


\cfcode{lidia\_size\_t}{a.length}{}
{
returns the number of base digits of the mantissa of \MATH{a}.}


\cfcode{lidia\_size\_t}{a.bit\_length}{}
{
returns the number of bits of the mantissa of \MATH{a}.}


\cfcode{int}{a.bit}{unsigned int i}
{
returns the \MATH{i}-th bit of \MATH{a}. Bits are numbered
from \MATH{0} to \TT{a.bit\_length()-1}, where the least
significant bit of \MATH{a} has index \MATH{0}. If \MATH{i \GEQ} 
\TT{a.bit\_length()}, the function always returns \MATH{0}.}


\cfcode{int}{a.sign}{}
{
returns -1, 0, 1 if \MATH{a <, =, >} 0, respectively.}


\cfcode{unsigned long}{a.least\_significant\_digit}{}
{
returns the least significant digit of \MATH{a} i.e. if the
mantissa of \MATH{a} is \MATH{[m_0,m_1,\LDOTS,m_{l-1}]} the
function returns \MATH{m_0} (see basic description, page 
\pageref{bigint_description}).}


\cfcode{unsigned long}{a.most\_significant\_digit}{}
{
returns the most significant digit of \MATH{a} i.e. if
the mantissa of \MATH{a} is \MATH{[m_0, m_1, \LDOTS, m_{l - 1}]}
the function returns \MATH{m_{l - 1}} (see basic description, page
\pageref{bigint_description}).}


\fcode{void}{a.absolute\_value}{}
{
\MATH{a = |a|}.}

\fcode{void}{a.abs}{}
{
\MATH{a = |a|}.}

\fcode{void}{seed}{const bigint \& a}
{
initializes the random number generator defined in the
kernel with \MATH{a}.}


\fcode{bigint}{randomize}{const bigint \& a}
{
returns a random value \MATH{r} by means of the random number
generator defined in the kernel; \MATH{r \IN [0, \LDOTS, a-1]} if
\MATH{a > 0} and \MATH{r \IN [a+1, \LDOTS, 0]} if \MATH{a < 0};
if \MATH{a} is equal to zero, the \TT{lidia\_error\_handler} will
be invoked.}


\fcode{void}{swap}{bigint \& a\k bigint \& b}
{ exchanges the values of \MATH{a} and \MATH{b}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\HIGH

\fcode{bigint}{dl}{const bigint \& a,const bigint \& b, const bigint \&p}
{
computes a solution to \MATH{a^x \EQUIV b} modulo \MATH{p}. The solution is given
in the range \MATH{0\LE x \LT p - 1} and is unique modulo the
order of \MATH{a} mod \MATH{p}. If \MATH{p} is not a prime number,
\TT{dl()} returns -1. If \MATH{b} is not in the subgroup
generated by \MATH{a}, \TT{dl()} returns -2. To use this function 
include LiDIA/dlp.h .}


\fcode{bool}{fermat}{const bigint \& a}
{
performs a probabilistic primality test on \MATH{a} using
Fermat's theorem (see \cite{cohen}). The return value will
be \FALSE, if the function recognizes \MATH{a} as composite;
otherwise, it will be \TRUE. For any input \MATH{a \LE 1}
this function returns \FALSE.}


\fcode{int}{integer\_log}{unsigned long x}
{
returns the position of the most significant bit in an
unsigned long. For non-zero \MATH{x}, the return value of this
function will be at least 1; it corresponds to the value
\MATH{\LFLOOR \log _2(x) \RFLOOR + 1}.}


\fcode{bool}{is\_prime}{const bigint \& a\k int n=10}
{
performs a probabilistic primality test on \MATH{a} using the
Miller-Rabin method (see \cite[page 415]{cohen}). If \MATH{a > 1},
then the return value \FALSE implies that \MATH{a} is composite.
If \MATH{a>1} and \TT{is\_prime(a,n)} returns \TRUE, then \MATH{a}
is probably a prime number. For any input \MATH{a \LE 1} the
return value of \TT{is\_prime(a,n)} is \FALSE .}


\fcode{int}{jacobi}{const bigint \& a\k const bigint \& b}
{
returns the value of the Jacobi symbol \MATH{( \FRAC{a}{b} )},
hence the Legendre symbol when \MATH{b} is an odd prime (see
\cite[page 28]{cohen}). The Legendre symbol is defined to be
\MATH{1} if \MATH{a} is a quadratic residue mod \MATH{b}, \MATH{1}
if \MATH{a} is a quadratic non-residue mod \MATH{b} and \MATH{0}
if \MATH{a} is a multiple of \MATH{b}.}


\fcode{void}{nearest}{bigint \& z\k  const bigint \& u\k const bigint \& v}
{
computes an integer \MATH{z} with minimal distance
\MATH{|\FRAC{u}{v} - z|} if \MATH{v \NEQ 0}. If there are two
possible values, the one with the absolutely greater value
will be chosen. If \MATH{v = 0}, the \TT{lidia\_error\_handler} will be
invoked.}


\fcode{bigint}{next\_prime}{const bigint \& a}
{
returns the least integer number greater than \MATH{a} that satisfies the
primality test in function \TT{is\_prime(a)}. For any input
\MATH{a \LE 1} this function returns \MATH{2}.}


\fcode{bigint}{previous\_prime}{const bigint \& a}
{
returns the greatest integer number smaller than \MATH{ a} that satisfies the
primality test in function \TT{is\_prime(a)}. For any input
\MATH{a \LE 2} this function returns \MATH{0}.}


\fcode{void}{power\_mod}{bigint \& res\k const bigint \& a\k const bigint \& n\k const bigint \& m\k  int err = 0}
{
calculates in \MATH{res} the least non-negative residue of
\MATH{a^n} modulo \MATH{m} (\MATH{res \EQUIV a^n} mod \MATH{m}, \MATH{0 \LE res \LT |m|})
using the right-to-left binary exponentiation method (see
\cite[page 8]{cohen}).

For negative exponents \MATH{n}, this function tries to
compute the multiplicative inverse of \MATH{\LEFT( a^{-n} \RIGHT )}.
If it does not exist and \MATH{err = 0}, then the \TT{lidia\_error\_handler}
will be invoked. If the multiplicative inverse does not exist and
\MATH{err \NEQ 0}, the gcd of \MATH{ a^{-n} } and \MATH{m} will be
assigned to \MATH{res} and the function terminates.}


\fcode{long}{power\_test}{bigint \& b\k const bigint \& a}
{
tests, whether \MATH{a} is a perfect power. If \MATH{a} is a
\MATH{k}-th power, then \MATH{b} is set to \MATH{k}-th root
(i.e.~\MATH{b^k=a}) and \MATH{k} is returned; otherwise the
function returns \MATH{-1}.}

\fcode{void}{ressol}{bigint \& r\k const bigint \& a, const bigint \& p}
{returns a square root \MATH{r} mod \MATH{p} with \MATH{0 \LE r \LT p} by using
 a method of Shanks. It is assumed that \MATH{p} is prime and \MATH{0 \LE a \LT p}.
 A further condition is that \MATH{p = 2^{s} * (2k+1) + 1} where \MATH{s} fits
 in a \TT{long}.} 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\STITLE{Greatest Common Divisor}

\fcode{bigint}{gcd}{const bigint \& a\k const bigint \& b}
{
returns the greatest common divisor (gcd) of \MATH{a} and
\MATH{b} as a positive \BF{bigint}.}


\fcode{bigint}{bgcd}{const bigint \& a\k const bigint \& b}
{
calculates the gcd of \MATH{a} and \MATH{b} as a positive 
\BF{bigint} using a binary method.}


\fcode{bigint}{dgcd}{const bigint \& a\k const bigint \& b}
{
calculates the gcd of \MATH{a} and \MATH{b} as a positive 
\BF{bigint} using Euclidian division and returns its value.}


\fcode{bigint}{xgcd}{bigint \& u\k bigint \& v\k const bigint \& a\k const bigint \& b}
{
returns the gcd of \MATH{a} and \MATH{b} as a positive \BF{bigint}
and computes coefficients \MATH{u} and \MATH{v} with 
\MATH{|u| \LE \FRAC{|b|}{2 gcd(a,b)}} and
\MATH{|v| \LE \FRAC{|a|}{2 gcd(a,b)}} such that
\TT{gcd(a, b)}\MATH{ = u * a + v * b}, i.e. using an extended
gcd algorithm.}


\fcode{bigint}{xgcd\_left}{bigint \& u\k const bigint \& a\k const bigint \& b}
{
returns the gcd of \MATH{a} and \MATH{b} as a positive \BF{bigint}
and computes a coefficient \MATH{u} such that for some
integer \MATH{t} \TT{gcd(a, b)}\MATH{ = u * a + t * b}.}


\fcode{bigint}{xgcd\_right}{bigint \& v\k const bigint \& a\k const bigint \& b}
{
returns the gcd of \MATH{a} and \MATH{b} as a positive \BF{bigint}
and computes a coefficient \MATH{v} such that for some 
integer \MATH{t} \TT{gcd(a, b)}\MATH{ = t * a + v * b}.}


\fcode{bigint}{lcm}{const bigint \& a\k const bigint \& b}
{
returns the least common multiple (lcm) of \MATH{a}
and \MATH{b} as a positive \BF{bigint}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\IO

Let \MATH{a} be of type \BF{bigint}.

The \BF{istream} operator \TT{>>} and  the \BF{ostream}  operator
\TT{<<} are overloaded. Furthermore, you can use the following
member functions for writing to and reading from a file in binary
or ASCII format, respectively.  The input and output format of a
\BF{bigint} consist only of the number itself without blanks. Note
that you have to manage by yourself that successive \BF{bigint}s
have to be separated by blanks. 


\fcode{void}{a.read\_from\_file}{FILE * fp}
{
reads \MATH{a} from the binary file \MATH{f\!p} using fread.}


\fcode{void}{a.write\_to\_file}{FILE * fp}
{
writes \MATH{a} to binary file \MATH{f\!p} using fwrite.}


\fcode{void}{a.scan\_from\_file}{FILE * fp}
{
scans \MATH{a} from the ASCII file \MATH{f\!p} using fscanf. 
We assume that the file contains the number in decimal
representation.}


\fcode{void}{a.print\_to\_file}{FILE * fp}
{
prints \MATH{a} in decimal representation to the ASCII file
\MATH{f\!p} using fprintf.}


The following functions allow conversion between \BF{bigint} values
and strings:


\fcode{int}{string\_to\_bigint}{const char *s\k bigint \& a}
{
converts the string \MATH{s} into the \BF{bigint} \MATH{a} and returns
the number of used characters.}


\fcode{int}{bigint\_to\_string}{const bigint \& a\k char *s}
{
converts the bigint \MATH{a} into the string \MATH{s} and
returns the number of used characters. The number of
characters allocated for string \MATH{s} must be at least
\TT{a.bit\_length()}/3 + 10.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\SEEALSO
UNIX manual page mp(3x)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NOTES
The member functions \TT{scan\_from\_file()}, \TT{print\_to\_file()}, 
\TT{read\_from\_file()} and \TT{write\_to\_file()} are included
because there are still C++ compilers which do not handle fstreams
correctly. In a future release those functions will disappear.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\EXAMPLES
\begin{verbatim}
 #include <LiDIA/bigint.h>

 int main()
 {

    bigint a, b, c;

    cout << "Please enter a : "; cin >> a ; 

    cout << "Please enter b : "; cin >> b ;

    cout << "\n";

    c = a + b;

    cout << "a + b = " << c << "\n";

 } 

\end{verbatim}

For further examples please refer to \\
\TT{LiDIA/src/interfaces/INTERFACE/bigint\_appl.c}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\AUTHOR
Thomas Papanikolaou


\end{lidia_man}



