diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-07-24 18:04:15 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-07-24 18:04:15 +0200 |
| commit | d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea (patch) | |
| tree | 2f27365f2c6490d1546c277ae503fb94c645d68b /doc | |
| parent | Add exercise: [▶M17] Factorials inverted (diff) | |
| download | libzahl-d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea.tar.gz libzahl-d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea.tar.bz2 libzahl-d89b4e54d7b4ee8aee05051ccf6e3b96019ac3ea.tar.xz | |
Add exercise: [▶02] Saturated subtraction
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | doc/exercises.tex | 32 |
1 files changed, 31 insertions, 1 deletions
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); |
