(wrong string) ée

From: <git_AT_suckless.org>
Date: Thu, 12 May 2016 01:25:14 +0200 (CEST)

commit a70f79dfb22e8ea00231f5739f89ecc8d552643f
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed May 11 22:26:27 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Wed May 11 22:26:27 2016 +0200

    On sign manipulation
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/doc/arithmetic.tex b/doc/arithmetic.tex
index e51d52f..bd761c4 100644
--- a/doc/arithmetic.tex
+++ b/doc/arithmetic.tex
_AT_@ -91,10 +91,10 @@ be detrimental to libzahl's simplicity.
 in-place operation:
 
 \begin{alltt}
- zadd(a, a, b);
- zadd(b, a, b); \textcolor{c}{/* \textrm{should be avoided} */}
- zadd_unsigned(a, a, b);
- zadd_unsigned(b, a, b); \textcolor{c}{/* \textrm{should be avoided} */}
+ zadd(a, a, b);
+ zadd(b, a, b); \textcolor{c}{/* \textrm{should be avoided} */}
+ zadd_unsigned(a, a, b);
+ zadd_unsigned(b, a, b); \textcolor{c}{/* \textrm{should be avoided} */}
 \end{alltt}
 
 \noindent
_AT_@ -137,4 +137,59 @@ TODO % zpow zpowu zmodpow zmodpowu
 \section{Sign manipulation}
 \label{sec:Sign manipulation}
 
-TODO % zabs zneg
+libzahl provides two functions for manipulating
+the sign of integers:
+
+\begin{alltt}
+ void zabs(z_t r, z_t a);
+ void zneg(z_t r, z_t a);
+\end{alltt}
+
+{\tt zabs} stores the absolute value of {\tt a}
+in {\tt r}, that is, it creates a copy of
+{\tt a} to {\tt r}, unless {\tt a} and {\tt r}
+are the same reference, and then removes its sign;
+if the value is negative, it becomes positive.
+
+\vspace{1em}
+\(
+ r \gets \lvert a \rvert =
+ \left \lbrace \begin{array}{rl}
+ -a & \quad \textrm{if}~a \le 0 \\
+ +a & \quad \textrm{if}~a \ge 0 \\
+ \end{array} \right .
+\)
+\vspace{1em}
+
+{\tt zneg} stores the negated of {\tt a}
+in {\tt r}, that is, it creates a copy of
+{\tt a} to {\tt r}, unless {\tt a} and {\tt r}
+are the same reference, and then flips sign;
+if the value is negative, it becomes positive,
+if the value is positive, it becomes negative.
+
+\vspace{1em}
+\(
+ r \gets -a
+\)
+\vspace{1em}
+
+Note that there is no function for
+
+\vspace{1em}
+\(
+ r \gets -\lvert a \rvert =
+ \left \lbrace \begin{array}{rl}
+ a & \quad \textrm{if}~a \le 0 \\
+ -a & \quad \textrm{if}~a \ge 0 \\
+ \end{array} \right .
+\)
+\vspace{1em}
+
+\noindent
+calling {\tt zabs} followed by {\tt zneg}
+should be sufficient for most users:
+
+\begin{alltt}
+ #define my_negabs(r, a) (zabs(r, a), zneg(r, r))
+\end{alltt}
Received on Thu May 12 2016 - 01:25:14 CEST

This archive was generated by hypermail 2.3.0 : Thu May 12 2016 - 01:36:20 CEST