Why does the samples option conflict with fp?
The max
code picks up a trailing \fi
a full fix would be to track down exactly where that hasn't been removed properly but a quick fix is to test for it and handle it in max:
\documentclass{amsart}
\usepackage{fp}
\usepackage{tikz}
\endlinechar=-1
\usetikzlibrary{fixedpointarithmetic}
\endlinechar=13
\makeatletter
\def\pgf@fitest{\fi}
\def\pgfmathfpmax@#1#2{%
\def\pgf@tmp{#2}%
\ifx\pgf@tmp\pgf@fitest
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\pgf@fitest\pgfmathfpmax@#1}%
{\begingroup%
\FPifgt{#1}{#2}%
\def\pgfmathresult{#1}%
\else%
\def\pgfmathresult{#2}%
\fi%
\pgfmath@smuggleone\pgfmathresult%
\endgroup%
}}
\let\pgfmathmax@=\pgfmathfpmax@%
\begin{document}
\begin{tikzpicture}[scale=2, fixed point arithmetic]
\draw[domain=0:360, samples=100] plot ({2*cos(\x)}, {sin(\x)});
\end{tikzpicture}
\end{document}
The problem is in the fixedpointarithmetic
that assumes \pgfmathmax@
expects two arguments. Instead, a construction such as \pgfmathparse{max(1,2,3)}
calls
\pgfmathmax@{{1}{2}{3}}
and it's the duty of \pgfmathmax@
to sort out the thing and find the maximum.
Since samples=<value>
does max(2,<value>)
the problem arises.
The fixedpointarithmetic
library does
\let\pgfmathmax@\pgfmathfpmax@
where the macro \pgfmathfpmax@
is defined with two arguments. Thus every time \pgfmathmax@
is called, it consumes one token more. One can easily fix the bug if max
is only computed between two numbers, but if a TikZ program wants max
between more than two quantities, it will break.
For instance
\begin{tikzpicture}[fixed point arithmetic]
\pgfmathparse{max(2,100,123)};
\end{tikzpicture}
will result in storing 100
in \pgfmathresult
and printing 123.
Calls of the function min
will break in the same way.
Also \pgfmathfpmax
is buggy: after \pgrmathfpmax{1}{2}
, the macro \pgfmathresult
will expand to \pgfmathresult
, not to 2
. The same for \pgfmathfpmin
.
A very partial fix for the particular problem is
\documentclass{amsart}
\usepackage{etoolbox}
\usepackage{fp}
\usepackage{tikz}
\usetikzlibrary{fixedpointarithmetic}
\makeatletter
% partial fix for the bug
\let\buggy@pgfmathfpmax@\pgfmathfpmax@
\def\pgfmathfpmax@#1{\buggy@pgfmathfpmax@#1}
% remove the bad \unskip tokens
\patchcmd\pgfmathfpscientific{\unskip}{}{}{}
\patchcmd{\pgfmathfppow@}{\unskip}{}{}{}
% remove the wrong space in \FP@pow
\patchcmd{\FP@pow}
{ }{}
{\typeout{Fixed \string\FP@pow}}
{\typeout{\noexpand\FP@pow needs no patch}}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=2, fixed point arithmetic]
\draw[domain=0:360, samples=99] plot ({2*cos(\x)}, {sin(\x)});
\end{tikzpicture}
\end{document}
However, this will only fix the particular call done when the samples
key is processed.
My advice is to forget about the fixedpointarithmetic
library until the bugs are fixed.
I added also a couple of safe fixes, for avoiding the creeping in of spaces, better than loading the library with \endlinechar=-1
.