(wrong string) ▶02] Saturated subtraction || Mattias Andrée

From: <git_AT_suckless.org>
Date: Mon, 25 Jul 2016 01:13:39 +0200 (CEST)

commit d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sun Jul 24 18:04:15 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sun Jul 24 18:04:15 2016 +0200

    Add exercise: [▶02] Saturated subtraction
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/doc/exercises.tex b/doc/exercises.tex
index 85e7439..cf222db 100644
--- a/doc/exercises.tex
+++ b/doc/exercises.tex
_AT_@ -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
_AT_@ -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,
_AT_@ -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);
Received on Mon Jul 25 2016 - 01:13:39 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 25 2016 - 01:24:26 CEST