From 7f7db96477549f03b6ed62fd9d5b1e24c1e67248 Mon Sep 17 00:00:00 2001 From: 3geek14 Date: Mon, 20 Sep 2021 12:49:18 -0400 Subject: [PATCH] manual: add warning about floating-point arithmetic #1050 Per a suggestion from @muzimuzhi on #1050, add a warning about floating-point arithmetic to the first introduction of `foreach` in Karl's tutorial. Signed-off-by: 3geek14 --- doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex b/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex index ae2c47cdc..f12173698 100644 --- a/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex +++ b/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex @@ -1100,11 +1100,16 @@ \subsection{Repeating Things: For-Loops} \end{codeexample} If you provide \emph{two} numbers before the |...|, the |\foreach| statement -will use their difference for the stepping: +will use their difference for the stepping, but be wary of floating-point +rounding errors: % \begin{codeexample}[] -\tikz \foreach \x in {-1,-0.5,...,1} - \draw (\x cm,-1pt) -- (\x cm,1pt); +\begin{tikzpicture} + \foreach \x in {-1,-0.5,...,1} + \draw (\x cm,-1pt) -- (\x cm,1pt); + \foreach \x in {-1,-0.8,...,1} + \draw (\x cm,-7pt) -- (\x cm,-5pt); +\end{tikzpicture} \end{codeexample} We can also nest loops to create interesting effects: