Ratio arithmetic in plain TeX

Graphics package has code to divide dimens:

enter image description here

\documentclass{article}

\usepackage{graphics}

\makeatletter

\begin{document}


\def\setdimenzerotofontheightanddepth#1#2{
\dimen8=\fontcharht\font`#1
\advance\dimen8 by \fontchardp\font`#1
\ifx#2
\else
  \advance\dimen8 by \fontcharht\font`#2
  \advance\dimen8 by \fontchardp\font`#2
\fi
}

\setdimenzerotofontheightanddepth fg

Dimen8 is: \the\dimen8, Baselineskip is: \the\baselineskip


\Gscale@div\tmp \baselineskip{\dimen8}

gives \tmp

The real (manually calculated ratio) is $0.90947\dots$



\end{document}

Here's a completely plain tex solution. It´s adapted from the graphics package.

\catcode`@=11

\begingroup
  \catcode`P=12
  \catcode`T=12
  \lowercase{
    \def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}}
  \expandafter\endgroup\x
\def\strip@pt{\expandafter\rem@pt\the}


\def\setdimenzerotofontheightanddepth#1#2{
\dimen8=\fontcharht\font`#1
\advance\dimen8 by \fontchardp\font`#1
\ifx#2
\else
  \advance\dimen8 by \fontcharht\font`#2
  \advance\dimen8 by \fontchardp\font`#2
\fi
}

\setdimenzerotofontheightanddepth fg%
\edef\dimzeroamt{\strip@pt\dimen8 %
}%

\dimen0=\baselineskip%
\count0=65536
  \loop%
  \ifdim\dimen0<8192\p@%
    \dimen0=2\dimen0%
    \divide\count0 by 2 %
  \repeat
\divide\dimen8\count0
\divide\dimen0\dimen8
\strip@pt\dimen0
%\edef\x{\strip@pt\dimen0}

The real (manually calculated ratio) is $0.90947\dots$%
\catcode`@=12

\bye

The syntax rules of TeX tell you that you can

\divide\dimen0 by <number>

where <number> is an integer. In your case, the expansion of \dimzeroamt is 13.19443, so TeX duly divides \dimen0 by 13 and prints .19443.

You can do it with expl3 (also in Plain TeX):

\input expl3-generic

\ExplSyntaxOn
\cs_new_protected:Nn \ioiooiioio_getfactor:Nnnn
 {% #1 is a control sequence, #2 the dimension, #3 and #4 two characters
  \tl_set:Nx #1
   {
    \fp_eval:n
     {
      \dim_to_fp:n { #2 } /
      \dim_to_fp:n
       {
        \fontcharht\font`#3 + \fontcharht\font`#4
        +
        \fontchardp\font`#3 + \fontchardp\font`#4
       }
     }
   }
 }
\cs_set_eq:NN \getfactor \ioiooiioio_getfactor:Nnnn
\ExplSyntaxOff

\getfactor\test{\baselineskip}{f}{g}

\test

\bye

enter image description here

I'm not sure you want to sum those dimensions; in case you want to use the maximum between heights and depths, change the lines in the second \dim_to_fp:n command to

       \dim_max:nn { \fontcharht\font`#3 } { \fontcharht\font`#4 }
       +
       \dim_max:nn { \fontchardp\font`#3 } { \fontchardp\font`#4 }