In this answer, I've been conservative and used the following code:
\expandafter\scalebox\expandafter{\my@scale}{\usebox{\my@box}}
to make sure not to rely on undocumented (?) behavior of \scalebox from the graphicx package (in case you are wondering, \my@scale has been defined with \pgfmathsetmacro). However, as shown in the following example, it seems that \scalebox fully expands at least its first argument, therefore I am considering if I should simplify the above line by removing the two \expandafter calls.
\documentclass{article}
\usepackage{graphicx}
\usepackage{xfp}
\newcommand*{\scalea}{0.5}
\newcommand*{\scaleb}{\scalebaux}
\newcommand*{\scalebaux}{\fpeval{0.5^2}}
\newsavebox{\mybox}
\sbox{\mybox}{\includegraphics{example-image}} % any box would do
\begin{document}
\scalebox{1.0}{\usebox{\mybox}}\par
\scalebox{\scalea}{\usebox{\mybox}}\par
\scalebox{\scaleb}{\usebox{\mybox}}
\end{document}
Questions
Is it considered to be part of the
\scaleboxAPI that it fully expands the two arguments giving scale factors, noted 〈h-scale〉 and 〈v-scale〉 in the below syntax reminder?\scalebox{〈h-scale〉}[〈v-scale〉]{〈text〉}If you answered “no”, is there any integer n > 0 such that at least n expansion steps are guaranteed to happen on the same two arguments?
Do the previous answers also apply when using:
\includegraphics{scale=...}{some-file}?
Thanks!

\hbox tocases and inside a\special, in the first two they'll be expanded because that's the way TeX works, in the\specialit'll be expanded\edeflike (in the special your input will be wrapped inside a\def\Gscale@xand\def\Gscale@yand only those are used inside the\special). – Skillmon Jun 28 '19 at 08:49\hbox to 〈dimen〉, it must be full expansion. What is the\specialused for here? And does it perform full expansion too? Thanks. – frougon Jun 28 '19 at 08:53\mark{..},\message{...},\errmessage{...},\special{...}, and\write<number>{...}all expand the token lists in braces almost exactly as\edefand\xdefdo." The difference is, that you don't need to double#inside those to put a single#in the argument. – Skillmon Jun 28 '19 at 08:55\specialor an equivalent whatsit such as \pdfliteral to inject PostScript or PDF transformations around the tex-generated output – David Carlisle Jun 28 '19 at 09:00\specialis used, and necessary, to implement the scaling operation? From what I've gathered in these comments, we have full expansion for both scale factors. If so, what remains for 1 and 2 in my question is, can we consider this fact to be part of the API? (I guess the answer is yes, to avoid breaking existing code) – frougon Jun 28 '19 at 09:19What is the \special used for herequestion. It is not so much a matter of not breaking existing code as I don't see how you could define this and avoid expansion. It is same as say\setlengththe length argument has to be expanded in the end to get a length. So even though\scaleboxdoesn't do anything special here the arguments get expanded because tex is a macro expansion language and that is what happens unless you stop it happening. – David Carlisle Jun 28 '19 at 09:24\scalebox-like macro that handles scale factors such as0.5e0without expanding any macro in the argument, only grabbing it token by token and analysing these. So, there is an API choice. I understand, though, that full expansion is part of the API from your POV. BTW, this explicit API aspect regarding expansion is one of the things I find tremendously better in LaTeX3 as compared to LaTeX2e. – frougon Jun 28 '19 at 09:29\dim_set:Nnnote the expression argument getsnnotxeven though (in the sense you mean here) it is fully expanded as the expansion is implied by its use as a length. So I wouldn't say it's any more explicit in this case. – David Carlisle Jun 28 '19 at 09:38\int_step_inline:nn, but this is the same catch). I've learnt this fact from egreg and find it convenient to use when coding. It just means that the syntax for 〈dimension expression〉 (or 〈integer expression〉) is very flexible: even complex expressions are already conformant to 〈dimension expression〉, before any expansion has been performed on them. But this fact is really part of the LaTeX3 API, IMHO. :-) – frougon Jun 28 '19 at 09:47\dimexpr...\relaxthere, same for<integer expression>is just a\numexpr, you could do the same in L2 (see thecalcpackage). – Skillmon Jun 28 '19 at 11:17\numexpr ... \relax(and ditto for 〈dimension expression〉 with\dimexpr...\relax), is IMO an implementation detail. When one knows it, one can easily deduce the API, but normally, both are distinct. A given API can in general be implemented in different ways, and most of the time, what matters for users (programmers) is the API, not the implementation details. Back to my question, the factors used by\scaleboxare... – frougon Jun 28 '19 at 11:55graphicxbeen written after\fp_eval:nbecame available—or something similar in the TeX engine. If I understood right, they are used as the 〈factor〉 of a 〈normal dimen〉, which is what prescribes the rules for what is allowed and what isn't. I thought this could be clearly stated as being the intended API, but won't insist anymore... – frougon Jun 28 '19 at 11:56