%%% \badness badness

\verb'\badness' parameter is supposed to tell something about box stretch or shrinkage,
or more precisely, about how far the available stretchability or shrinkability has been used.
\verb'\badness'=0 means no stretch or shrink used, 100 means the entire flexibility consumed,
more then 100 denotes undefull or overfull box (the later with \verb'\badness' equal $1\,000\,000$).
So \verb'\badness' certaintly says something about how the content fits the box, but one
may be surprised by fine artifacts of the actual algorithm. Lets take a macro that measures
\verb'\vbox' \verb'\badness', taking the actual and the available stretch as arguments.

\beginverbatim
\def\test#1#2{% <actual_stretch> <available_stretch>
  \setbox0\vbox to\dimexpr#1{\vskip0pt plus\dimexpr#2}%
  \immediate\write16{badness=\the\badness, \the\ht0}}
\endverbatim

\beginverbatim
\test{100pt-1sp}{100pt}  % \badness=99
\test{100pt}{100pt}      % 100
\test{100pt+1sp}{100pt}  % 100
\test{100.3366pt}{100pt} % 100
\test{100.3367pt}{100pt} % 101
\endverbatim

Note that we never get \verb'\badness' equal 100 if the actual
stretch is even 1sp smaller then the available stretch.
But \TeX\ seems to ignore the stretch abuse around 0.0033 and less.

OK so far. Now lets take such insignificantly underfull box of
299sp actual, and 298sp available stretch. We will scale those
values with integer in factor.

\beginverbatim
\def\scale#1{\test{299sp*#1}{298sp*#1}}
\scale{1} % 100
\scale{2} % 100
\scale{3} % 100
...
\scale{24182} % 101
\scale{24184} % 101
...
\scale{24948} % 100
\endverbatim

\verb'\badness' varies although we keep the stretch ratio fixed!

All because heuristic \verb'\badness' formula ({\tt tex.web}, line 2320):

%   @d inf_bad = 10000 {infinitely bad value}
%   @p function badness(@!t,@!s:scaled):halfword; {compute badness, given |t>=0|}
%   var r:integer; {approximation to $\alpha t/s$, where $\alpha^3\approx
%     100\cdot2^{18}$}
\beginverbatim
...
begin if t=0 then badness:=0
else if s<=0 then badness:=inf_bad
else
	begin if t<=7230584 then  r:=(t*297) div s {$297^3=99.94\times2^{18}$}
	else if s>=1663497 then r:=t div (s div 297)
...
\endverbatim
% 	  else r:=t;
%     if r>1290 then badness:=inf_bad {$1290^3<2^{31}<1291^3$}
%     else badness:=(r*r*r+@'400000) div @'1000000;
%     end; {that was $r^3/2^{18}$, rounded to the nearest integer}
%   end;