47 lines
1.4 KiB
TeX
47 lines
1.4 KiB
TeX
\section{Approximation}
|
|
|
|
\definition{}
|
|
Say we have a bit string $x$. \par
|
|
Let $x_f$ denote the value of $x$ interpreted as a float, \par
|
|
and let $x_i$ denote the value of $x$ interpreted as an integer.
|
|
|
|
\problem{}
|
|
Let $x = \texttt{0b01000001\_01001000\_00000000\_00000000}$. \
|
|
What are $x_f$ and $x_i$?
|
|
|
|
\begin{solution}
|
|
$x_f = 12.5$ \par
|
|
\vspace{2mm}
|
|
$x_i = 2^{30} + 2^{24} + 2^{22} + 2^{19} = 11,095,237,632$
|
|
\end{solution}
|
|
|
|
|
|
\generic{Observation:}
|
|
For small values of $a$, $\log_2(1 + a)$ is approximately equal to $a$. \par
|
|
Note that this equality is exact for $a = 0$ and $a = 1$, since $\log_2(1) = 0$ and $\log_2(2) = 1$.
|
|
|
|
\vspace{2mm}
|
|
|
|
We'll add a \say{correction term} $\varepsilon$ to this approximation, so that $\log_2(1 + a) \approx a + \varepsilon$.
|
|
|
|
TODO: why? Graphs.
|
|
|
|
\problem{}
|
|
Use the fact that $\log_2(1 + a) \approx a + \varepsilon$ to approximate $\log_2(x_f)$ in terms of $x_i$, \par
|
|
|
|
|
|
\begin{solution}
|
|
Let $E$ and $F$ be the exponent and float bits of $x_f$. \par
|
|
We then have:
|
|
\begin{align*}
|
|
\log_2(x_f)
|
|
&=~ \log_2 \left( 2^{E-127} \times \left(1 + \frac{F}{2^{23}}\right) \right) \\
|
|
&=~ E-127 + \log_2\left(1 + \frac{F}{2^{23}}\right) \\
|
|
&\approx~ E-127 + \frac{F}{2^{23}} + \varepsilon \\
|
|
&=~ \frac{1}{2^{23}}(2^{23}E + F) - 127 + \varepsilon \\
|
|
&=~ \frac{1}{2^{23}}(x_i) - 127 + \varepsilon
|
|
\end{align*}
|
|
\end{solution}
|
|
|
|
\vfill
|
|
\pagebreak |