Skip to content

Commit

Permalink
manual: add warning about floating-point arithmetic #1050
Browse files Browse the repository at this point in the history
Per a suggestion from @muzimuzhi on #1050, add a warning about floating-point arithmetic
to the first introduction of `foreach` in Karl's tutorial.
  • Loading branch information
3geek14 committed Sep 20, 2021
1 parent a497067 commit 8b02a24
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b02a24

Please sign in to comment.