Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning about floating-point arithmetic to foreach introduction #1053

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 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,17 @@ \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.9,...,0}
% tick at 0 is not drawn due to rounding errors
\draw (\x cm,-7pt) -- (\x cm,-5pt);
\end{tikzpicture}
\end{codeexample}

We can also nest loops to create interesting effects:
Expand Down