# fixed point arithmetic is all wacky now [closed]

Prior to Tikz 3.0, the use of \usepackage{fp}\usetikzlibrary{fixedpointarithmetic} would increase the accuracy of calculations.

I haven't used these packages since the update. However, I tried them out today and the results were nonsense.

Why is fixed point arithmetic affecting 3 sides of my box of mass M and under estimating the arc?

Also, the vectors off the box are based on the location of the box. How can the vectors remain unchanged when the box has moved?

I used fixed point arithmetic on calculating angles in the \draw let syntax.

\draw[-stealth, fixed point arithmetic] let
\p0 = (O),
\p1 = (P1),
\p2 = (P2),
\n1 = {atan2(\y1 - \y0, \x1 - \x0)},
\n2 = {atan2(\y2 - \y0, \x2 - \x0)},
\n3 = {1cm},
\n4 = {(\n1 + \n2)/2}
in \pgfextra{\xdef\myn{\n2}} (O) +(\n1:\n3) arc[radius = \n3,
start angle = \n1, end angle = \n2] node[right, font = \tiny] at (\n4:\n3)
{$\theta$};

Without fixed point arithmetic, the image is:

With:

Code:

\documentclass[tikz, convert = false]{standalone}%

\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds}

\begin{document}
\begin{tikzpicture}[line join = round, line cap = round]
\coordinate (O) at (0, 0);

\draw (O) -- +(3, 0) coordinate (P1);
\draw[name path = sline] (O) -- (3, 2) coordinate (P2);

\draw[-stealth, fixed point arithmetic] let % remove fpa for it work
\p0 = (O),
\p1 = (P1),
\p2 = (P2),
\n1 = {atan2(\y1 - \y0, \x1 - \x0)},
\n2 = {atan2(\y2 - \y0, \x2 - \x0)},
\n3 = {1cm},
\n4 = {(\n1 + \n2)/2}
in \pgfextra{\xdef\myn{\n2}} (O) +(\n1:\n3) arc[radius = \n3,
start angle = \n1, end angle = \n2] node[right, font = \tiny] at (\n4:\n3)
{$\theta$};

\path[name path = line1] (1.5, 0) -- +(0, 1.25);
\path[name path = line2] (2, 0) -- +(0, 1.5);
\path[name intersections = {of = sline and line1, by = P3}];
\path[name intersections = {of = sline and line2, by = P4}];

\draw (P3) -- ($(P3)!.25cm!-90:(O)$) coordinate (P5);
\draw (P4) -- ($(P4)!.25cm!-90:(O)$) coordinate (P6);
\draw[name path = boxtop] (P5) -- (P6) node[pos = .5, below, font = \tiny,
rotate = \myn] {$M$};

\path[name path = grav] ($(P5)!.75!(P6)$) -- +(0, -1.25);
\path[name intersections = {of = grav and sline, by = P7}];

\begin{scope}[on background layer]
\draw[-latex, blue] (P7) -- ($(P7)!.75cm!-270:(O)$) coordinate (P8)
node[pos = 1.25, font = \tiny, color = black] {$F_2$};

\path[name path = perl1] (P8) -- ($(P8)!.75cm!-270:(P7)$);
\path[name intersections = {of = perl1 and grav, by = P9}];

\draw[-latex, blue] (P7) -- (P9) node[below, font = \tiny, inner sep = .3,
color = black] {$Mg$};
\draw[blue] (P9) -- (P8);

\path[name path = norm] (P7) -- ($(P7)!.75cm!-90:(O)$);
\path[name intersections = {of = norm and boxtop, by = P10}];

\draw[-latex,blue] (P10) -- ($(P10)!.5cm!-90:(P5)$) node[pos = 1.15,
font = \tiny, rotate = {\myn}, color = black] {$N$};

\coordinate (P11) at ($(P3)!.5!(P5)$);
\coordinate (P12) at ($(P4)!.5!(P6)$);

\draw[-latex, blue] (P12) -- ++(\myn:.5) node[pos = 1.25, font = \tiny,
rotate = {\myn}, color = black] {$F_f$};
\draw[-latex, blue] (P11) -- ++({\myn + 180}:.5) node[pos = 1.25,
font = \tiny, rotate = {\myn}, color = black] {$F_1$};
\end{scope}
\end{tikzpicture}
\end{document}
-

## closed as off-topic by Werner, Andrew Swann, Heiko Oberdiek, Thorsten, cmhughesApr 27 '14 at 15:59

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Not inherent to the problem, but are you aware of the angles library? – Claudio Fiandrino Apr 25 '14 at 18:07
@ClaudioFiandrino I have never used that library. – dustin Apr 25 '14 at 18:15
@dustin: it just makes your job easier ;) – Claudio Fiandrino Apr 25 '14 at 18:20
@TorbjørnT. here using fp isn't important, but when I want to have pgf calculate and print the angles (in other problems), using fp improves the printed value significantly in some cases. – dustin Apr 25 '14 at 18:20
This question appears to be off-topic because it is about a bug that has been reported. – Werner Apr 27 '14 at 15:17

It is a bug in pgflibraryfixedpointarithmetic.code.tex (tested with TikZ 3.0; file size 13595 bytes) caused by a space at line end in macro definition \pgfmathfpabs@:

\def\pgfmathfpabs@#1{%
\begingroup%
\FPabs\pgfmathresult{#1}
\pgfmath@smuggleone\pgfmathresult%
\endgroup%
}

The space is after the third line. Corrected version:

\def\pgfmathfpabs@#1{%
\begingroup%
\FPabs\pgfmathresult{#1}%
\pgfmath@smuggleone\pgfmathresult%
\endgroup%
}

The code for atan2 uses function abs twice. The inserted spaces causes the following elements to the right; the origin is no longer in (0,0), but moved to the right.

The definitions of \pgfmathfpsec@ and \pgfmathfpcosec suffer from the same problems.

Workaround:

\endlinechar=-1
\usetikzlibrary{fixedpointarithmetic}
\endlinechar=13

MWE:

\documentclass[tikz, convert = false]{standalone}%

\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}

\path[
fixed point arithmetic
] let
\n1 = {atan2(57pt, 85pt)}
in;

\end{tikzpicture}
\end{document}

Without fix:

With fix:

-
– Heiko Oberdiek Apr 27 '14 at 13:34
Awesome thanks. I knew there was something wrong. – dustin Apr 27 '14 at 15:11
I got feedback: The bug is now fixed and closed. – Heiko Oberdiek May 6 '14 at 22:14
Has the package been updated in TeX Live? The answer is no. I just ran the updated and no packages were updated. – dustin May 6 '14 at 22:14
I doubt it. That the bug is fixed does not mean there is an immediate new release of the whole package. I do not know, when the next release is planned. – Heiko Oberdiek May 6 '14 at 22:16

Using a scope only for the calculation of atan2 works for me. This scope seems to be necessary, but I do not know why.

\documentclass[tikz, convert = false]{standalone}%

\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds}

\begin{document}
\begin{tikzpicture}[line join = round, line cap = round]
\coordinate (O) at (0, 0);

\draw (O) -- +(3, 0) coordinate (P1);
\draw[name path = sline] (O) -- (3, 2) coordinate (P2);

\begin{scope}
\path[fixed point arithmetic] let
\p0 = (O),
\p1 = (P1),
\p2 = (P2),
\n1 = {atan2(\y1 - \y0, \x1 - \x0)},
\n2 = {atan2(\y2 - \y0, \x2 - \x0)}
in \pgfextra{\xdef\mym{\n1}\xdef\myn{\n2}};
\end{scope}

\draw[-stealth] let
\n3 = {1cm},
\n4 = {(\mym + \myn)/2} in
start angle = \mym, end angle = \myn] node[right, font = \tiny] at (\n4:\n3)
{$\theta$};

\path[name path = line1] (1.5, 0) -- +(0, 1.25);
\path[name path = line2] (2, 0) -- +(0, 1.5);
\path[name intersections = {of = sline and line1, by = P3}];
\path[name intersections = {of = sline and line2, by = P4}];

\draw (P3) -- ($(P3)!.25cm!-90:(O)$) coordinate (P5);
\draw (P4) -- ($(P4)!.25cm!-90:(O)$) coordinate (P6);
\draw[name path = boxtop] (P5) -- (P6) node[pos = .5, below, font = \tiny,
rotate = \myn] {$M$};

\path[name path = grav] ($(P5)!.75!(P6)$) -- +(0, -1.25);
\path[name intersections = {of = grav and sline, by = P7}];

\begin{scope}[on background layer]
\draw[-latex, blue] (P7) -- ($(P7)!.75cm!-270:(O)$) coordinate (P8)
node[pos = 1.25, font = \tiny, color = black] {$F_2$};

\path[name path = perl1] (P8) -- ($(P8)!.75cm!-270:(P7)$);
\path[name intersections = {of = perl1 and grav, by = P9}];

\draw[-latex, blue] (P7) -- (P9) node[below, font = \tiny, inner sep = .3,
color = black] {$Mg$};
\draw[blue] (P9) -- (P8);

\path[name path = norm] (P7) -- ($(P7)!.75cm!-90:(O)$);
\path[name intersections = {of = norm and boxtop, by = P10}];

\draw[-latex,blue] (P10) -- ($(P10)!.5cm!-90:(P5)$) node[pos = 1.15,
font = \tiny, rotate = {\myn}, color = black] {$N$};

\coordinate (P11) at ($(P3)!.5!(P5)$);
\coordinate (P12) at ($(P4)!.5!(P6)$);

\draw[-latex, blue] (P12) -- ++(\myn:.5) node[pos = 1.25, font = \tiny,
rotate = {\myn}, color = black] {$F_f$};
\draw[-latex, blue] (P11) -- ++({\myn + 180}:.5) node[pos = 1.25,
font = \tiny, rotate = {\myn}, color = black] {$F_1$};
\end{scope}
\end{tikzpicture}
\end{document}

In this example the fixed point arithmetic option could also be an argument of the scope or the picture, but in every case I have to use this extra scope for the calculation of atan2.

\begin{tikzpicture}[line join = round, line cap = round,
fixed point arithmetic
]
...
\begin{scope}
\path let
\p0 = (O),
\p1 = (P1),
\p2 = (P2),
\n1 = {atan2(\y1 - \y0, \x1 - \x0)},
\n2 = {atan2(\y2 - \y0, \x2 - \x0)}
in \pgfextra{\xdef\mym{\n1}\xdef\myn{\n2}};
\end{scope}

\draw[-stealth] let
\n3 = {1cm},
\n4 = {(\mym + \myn)/2} in
start angle = \mym, end angle = \myn] node[right, font = \tiny] at (\n4:\n3)
{$\theta$};
...

The result is the same as above.

-
In a post maybe 6 months or more ago, I learned not to put fixed point as the picture option. It can cause issue in some cases with nodes. – dustin Apr 27 '14 at 2:48
I reread yesterday the pgftikz manual and page 360 one can read "The best way to use this key is as an argument to a scope or picture." I remember it at sleeping time but this morning esdd had the same idea. – Tarass Apr 27 '14 at 6:41

Not the answer but I don't think you need fp here. The result is pretty accurate with PGF itself too.

\documentclass[tikz]{standalone}
\usetikzlibrary{angles,quotes,calc}
\begin{document}
\begin{tikzpicture}
% Angle label
\draw (0,0) coordinate (O) -- +(3, 0) coordinate (P1) (O)-- +(3, 2) coordinate (P2)
pic ["$\theta$",draw,->,angle eccentricity=1.2,angle radius=1cm] {angle = P1--O--P2};
% Angle value
\path let \p1=($(P2)-(O)$),\n1={atan2(\y1,\x1)} in \pgfextra{\xdef\myn{\n1}};
% Mass placement
\node[minimum width=1cm,draw,anchor=south,rotate=\myn] (m) at ($(O)!0.7!(P2)$) {M};
% Ortho-Forces
\foreach \x[count=\xi from 0] in {F_f,N,F_1,F_2}{
\draw[-latex,draw=blue] (m.\xi*90) --++(\xi*90+\myn:5mm)
node[,inner sep=2pt,anchor=90*(\xi+3),font=\tiny] {$\x$};
}
% Gravity
\draw[-latex,draw=blue] (m.south) --++(0,{-1/cos(\myn)*5mm}) node[font=\tiny,left] (mg) {$mg$};
% Tangential component
\draw[blue] (mg.east) -- ++(\myn:{tan(\myn)*5mm});
\end{tikzpicture}
\end{document}

-
I know fp isn't needed here. I general only use it when I print an angle. I decided to try it though since TikZ was updated. – dustin Apr 27 '14 at 15:13