While creating some pgfmathsetmacro arithmetic macros, I stumbled upon a very perplexing result. Take the following example:
\documentclass{article}
\usepackage{tikz}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\newcommand{\boxWidth}{6cm};
\newcommand{\boxHeight}{1cm};
\pgfmathsetmacro{\boxOffset}{\boxWidth / 2cm * 1cm} %%%wtf
\coordinate (Title) at (1cm + \boxOffset,0);
\draw [red] (0,0) -- (1,0);
\node[draw, rounded corners=.3cm, color=red, minimum width=\boxWidth, minimum height=\boxHeight, text=black] at (Title) {Hello};
\end{tikzpicture}
\end{document}
This outputs a very predictable result:

However, if you remove * 1cm from my \boxOffset macro, a totally unexpected result occurs:

What?! On the surface, this appears to be saying that 2 * 1 != 2 is a true statement!
To add to this, while I was playing around with creating an example LaTeX script for the following question on this forum, I stumbled upon a similar bamboozling arithmetic:
\documentclass{article}
\usepackage{tikz}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\newcommand{\str}{hello};
\pgfmathsetmacro{\numOne}{width("\str") * 1pt / 4cm}; %%%wtf
\node at (0, 0) {\str};
\draw [color=black] (\numOne, 0cm) -- (\numOne,-1cm);
\end{tikzpicture}
\end{document}
The following example creates the very predictable output:
However, if I change the \numOne to compute the following width("\str") * 1pt / 2cm / 2cm, then I get a very unpredictable output:
What?! This is telling me that the ridiculous statement x / 2 / 2 != x / 4 is true.
Can anyone shed some light on what is happening here? This is not the only time I have run into this bamboozling arithmetic and I am lost at what is happening.
^This is how I feel right now.




pt, so the1cmis converted to28.45274pt. – Phelype Oleinik Oct 11 '18 at 22:00pt; with*1cmyou get85.35823, without it is3.0; the quotient is28.45274, which is the number of points in 1cm. – egreg Oct 11 '18 at 22:00