\myheading{Base conversion}

FYL2X and F2XM1 instructions are the only logarithm-related x87 FPU has.
Nevertheless, it's possible to compute logarithm with any other base, using these.
The very important property of logarithms is:

\begin{equation}
\log_y (x) = \frac{\log_a (x)}{\log_a (y)}
\end{equation}

So, to compute common (base 10) logarithm using available x87 FPU instructions, we may use this equation:

\begin{equation}
\log_{10} (x) = \frac{\log_2 (x)}{\log_2 (10)}
\end{equation}

\dots while $\log_2(10)$ can be precomputed ahead of time.

Perhaps, this is the very reason, why x87 FPU has the following instructions:
FLDL2T (load $\log_2 (10)=3.32193...$ constant) and FLDL2E (load $\log_2 (e)=1.4427...$ constant).

Even more than that.
Another important property of logarithms is:

\begin{equation}
\log_y (x) = \frac{1}{\log_x (y)}
\end{equation}

Knowing that, and the fact that x87 FPU has FYL2X instruction (compute $y \cdot log_2 x$), logarithm base conversion can be done using multiplication:

\begin{equation}
\log_y (x) = \log_a (x) \cdot \log_y (a)
\end{equation}

So, computing common (base 10) logarithm on x87 FPU is:

\begin{equation}
\log_{10} (x) = \log_2 (x) \cdot \log_{10} (2)
\end{equation}

Apparently, that is why x87 FPU has another pair of instructions:

FLDLG2 (load $\log_{10} (2)=0.30103...$ constant) and FLDLN2 (load $\log_e (2)=0.693147...$ constant).

Now the task of computing common logarithm can be solved using just two FPU instructions: FYL2X and FLDLG2.

This piece of code I found inside of Windows NT4 ( \texttt{src/OS/nt4/private/fp32/tran/i386/87tran.asm} ), 
this function is capable of computing both common and natural logarithms: 

\begin{lstlisting}[caption=Assembly language code,style=customasmx86]
lab fFLOGm
        fldlg2                          ; main LOG10 entry point
        jmp     short fFYL2Xm

lab fFLNm                               ; main LN entry point
        fldln2

lab fFYL2Xm
        fxch
        or      cl, cl                  ; if arg is negative
        JSNZ    Yl2XArgNegative         ;    return a NAN
        fyl2x                           ; compute y*log2(x)
        ret
\end{lstlisting}


