Add exercise: [▶02] Saturated subtraction - libzahl - big integer library
 (HTM) git clone git://git.suckless.org/libzahl
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea
 (DIR) parent dbb82e8a1184eaa7f6fa4b04e0560589cc6092e9
 (HTM) Author: Mattias Andrée <maandree@kth.se>
       Date:   Sun, 24 Jul 2016 18:04:15 +0200
       
       Add exercise: [▶02] Saturated subtraction
       
       Signed-off-by: Mattias Andrée <maandree@kth.se>
       
       Diffstat:
         M doc/exercises.tex                   |      32 ++++++++++++++++++++++++++++++-
       
       1 file changed, 31 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/doc/exercises.tex b/doc/exercises.tex
       @@ -22,6 +22,22 @@
        \begin{enumerate}[label=\textbf{\arabic*}.]
        
        
       +
       +\item {[$\RHD$\textit{02}]} \textbf{Saturated subtraction}
       +
       +Implement the function
       +
       +\vspace{-1em}
       +\begin{alltt}
       +   void monus(z_t r, z_t a, z_t b);
       +\end{alltt}
       +\vspace{-1em}
       +
       +\noindent
       +which calculates $a \dotminus b = \max \{ 0,~ a - b \}$.
       +
       +
       +
        \item {[\textit{M10}]} \textbf{Convergence of the Lucas Number ratios}
        
        Find an approximation for
       @@ -122,6 +138,20 @@ Use this to implement a fast primality tester.
        
        \begin{enumerate}[label=\textbf{\arabic*}.]
        
       +\item \textbf{Saturated subtraction}
       +
       +\vspace{-1em}
       +\begin{alltt}
       +void monus(z_t r, z_t a, z_t b)
       +\{
       +    zsub(r, a, b);
       +    if (zsignum(r) < 0)
       +        zsetu(r, 0);
       +\}
       +\end{alltt}
       +
       +
       +
        \item \textbf{Convergence of the Lucas Number ratios}
        
        It would be a mistake to use bignum, and bigint in particular,
       @@ -243,7 +273,7 @@ enum zprimality ptest_fast(z_t p)
            z_t a;
            int c = zcmpu(p, 2);
            if (c <= 0)
       -      return c ? NONPRIME : PRIME;
       +        return c ? NONPRIME : PRIME;
            zinit(a);
            zsetu(a, 1);
            zlsh(a, a, p);