From 7f7db96477549f03b6ed62fd9d5b1e24c1e67248 Mon Sep 17 00:00:00 2001 From: 3geek14 Date: Mon, 20 Sep 2021 12:49:18 -0400 Subject: [PATCH 1/2] 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: From 6e0700b955b8e8f799f038c1232a7a91d69364e8 Mon Sep 17 00:00:00 2001 From: 3geek14 Date: Sat, 25 Sep 2021 13:03:00 -0400 Subject: [PATCH 2/2] Update doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex Co-authored-by: muzimuzhi --- doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex b/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex index f12173698..233b4bf81 100644 --- a/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex +++ b/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex @@ -1107,7 +1107,8 @@ \subsection{Repeating Things: For-Loops} \begin{tikzpicture} \foreach \x in {-1,-0.5,...,1} \draw (\x cm,-1pt) -- (\x cm,1pt); - \foreach \x in {-1,-0.8,...,1} + \foreach \x in {-1,-0.9,...,0} + % tick at 0 is not drawn due to rounding errors \draw (\x cm,-7pt) -- (\x cm,-5pt); \end{tikzpicture} \end{codeexample}