# tikz computation dimension too large square of x

I want to make extensive trigonometric computation involving coordinates on a diagram with a circle having a variable radius. Way too quickly, with radius value of 5, I got "dimension too large" errors. Here is my MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\tikzmath{\carre= \xb*\xb;}

\pgfmathsetmacro\rayon{sqrt(\xb*\xb +\yb*\yb)}

\tikzmath{\rayon= sqrt(\xb*\xb +\yb*\yb);}

\node at (-\r,-3) {rayon=\rayon};

\end{tikzpicture}
\end{document}


You can use the xfp package for the calculation of big numbers instead:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{xfp}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\edef\carre{\fpeval{\xb*\xb}pt}

\edef\rayon{\fpeval{sqrt(\xb*\xb + \yb*\yb)}pt}

\node at (-\r,-3) {rayon=\rayon};

\end{tikzpicture}
\end{document}


You can also use the fpu of TikZ, but it has to be activated:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\pgfset{fpu=true,fpu/output format=fixed}
\tikzmath{\carre= \xb*\xb;}

\pgfmathsetmacro\rayon{sqrt(\xb*\xb +\yb*\yb)}

\tikzmath{\rayon= sqrt(\xb*\xb +\yb*\yb);}
\pgfset{fpu=false} % hopefully this fixes the issues of github.com/pgf-tikz/pgf/issues/678

\node at (-\r,-3) {rayon=\rayon pt};

\end{tikzpicture}
\end{document}


Use the let operation.

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};
\draw ($(C) + (0:{\r})$) arc (0:\angleTheta:\r) coordinate (ref);
\path let \p1=(ref),
%\n{carre}={\x1*\x1},
\n{rayon}={veclen(\x1,\y1)}
in
node at (-\r,-1) {xb=\x1}
node at (-\r,-2) {yb=\y1}
node at (-\r,-3) {rayon=\n{rayon}};

\end{tikzpicture}
\end{document} 