From a9388ee62cd0553aa62f7305956b37d677d23c97 Mon Sep 17 00:00:00 2001
From: Mattias Andrée <maandree@kth.se>
Date: Sat, 14 May 2016 17:01:55 +0200
Subject: On bit-truncation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Mattias Andrée <maandree@kth.se>
---
 doc/bit-operations.tex | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

(limited to 'doc/bit-operations.tex')

diff --git a/doc/bit-operations.tex b/doc/bit-operations.tex
index 3f2938d..44fc27d 100644
--- a/doc/bit-operations.tex
+++ b/doc/bit-operations.tex
@@ -88,7 +88,30 @@ whenever possible. One such wrapper could be
 \section{Truncation}
 \label{sec:Truncation}
 
-TODO % ztrunc
+In \secref{sec:Shift} we have seen how bit-shift
+operations can be used to multiply or divide by a
+power of two. There is also a bit-truncation
+operation: {\tt ztrunc}, which is used to keep
+only the lowest bits, or equivalently, calculate
+the remainder of a division by a power of two.
+
+\begin{alltt}
+   void ztrunc(z_t r, z_t a, size_t b);
+\end{alltt}
+
+\noindent
+is consistent with {\tt zmod}; like {\tt zlsh} and
+{\tt zrsh}, {\tt a}'s sign is preserved into {\tt r}
+assuming the result is non-zero.
+
+{\tt ztrunc(r, a, b)} stores only the lowest {\tt b}
+bits in {\tt a} into {\tt r}, or equivalently,
+calculates $r \gets a \mod 2^b$. For example, if
+
+$a = 100011000_2$ then
+
+$r = \phantom{10001}1000_2$ after calling
+{\tt ztrunc(r, a, 4)}.
 
 
 \newpage
-- 
cgit v1.2.3-70-g09d2

