commit d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea
Author:     Mattias Andrée <[email protected]>
AuthorDate: Sun Jul 24 18:04:15 2016 +0200
Commit:     Mattias Andrée <[email protected]>
CommitDate: Sun Jul 24 18:04:15 2016 +0200

    Add exercise: [▶02] Saturated subtraction
    
    Signed-off-by: Mattias Andrée <[email protected]>

diff --git a/doc/exercises.tex b/doc/exercises.tex
index 85e7439..cf222db 100644
--- 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);

Reply via email to