Skip to content

Commit 8b02a24

Browse files
committed
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.
1 parent a497067 commit 8b02a24

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,11 +1100,16 @@ \subsection{Repeating Things: For-Loops}
11001100
\end{codeexample}
11011101

11021102
If you provide \emph{two} numbers before the |...|, the |\foreach| statement
1103-
will use their difference for the stepping:
1103+
will use their difference for the stepping, but be wary of floating-point
1104+
rounding errors:
11041105
%
11051106
\begin{codeexample}[]
1106-
\tikz \foreach \x in {-1,-0.5,...,1}
1107-
\draw (\x cm,-1pt) -- (\x cm,1pt);
1107+
\begin{tikzpicture}
1108+
\foreach \x in {-1,-0.5,...,1}
1109+
\draw (\x cm,-1pt) -- (\x cm,1pt);
1110+
\foreach \x in {-1,-0.8,...,1}
1111+
\draw (\x cm,-7pt) -- (\x cm,-5pt);
1112+
\end{tikzpicture}
11081113
\end{codeexample}
11091114

11101115
We can also nest loops to create interesting effects:

0 commit comments

Comments
 (0)