edits
Some checks failed
CI / Typst formatting (pull_request) Successful in 6s
CI / Typos (pull_request) Failing after 7s
CI / Build (pull_request) Has been skipped

This commit is contained in:
Mark 2025-02-08 18:22:28 -08:00
parent 459893843b
commit 3e3dbdbef5

View File

@ -14,23 +14,25 @@ float Q_rsqrt( float number ) {
}
\end{lstlisting}
This code defines
a function \texttt{Q\_rsqrt} that consumes a float named
This code defines a function \texttt{Q\_rsqrt} that consumes a float named
\texttt{number} and approximates its inverse square root (in other words, \texttt{Q\_rsqrt} computes $1/\sqrt{\texttt{number}}$).
\vspace{2mm}
If we rewrite this using the notation we're familiar with, we get the following:
If we rewrite this using notation we're familiar with, we get the following:
\begin{equation*}
\texttt{Q\_sqrt}(n_i) = 6240089 - (n_i \div 2) \approx \frac{1}{\sqrt{n_f}}
\texttt{Q\_sqrt}(n_f) = 6240089 - (n_i \div 2) \approx \frac{1}{\sqrt{n_f}}
\end{equation*}
$6240089$ is the decimal value of hex \texttt{0x5f3759df}. \par
It is a magic number hard-coded into the function.
\note{
\texttt{0x5f3759df} is $6240089$ in hexadecimal. \par
It is a magic number hard-coded into \texttt{Q\_sqrt}.
}
\vspace{2mm}
Our goal in this section is to understand why this works. \par
How are we able to approximate $\frac{1}{\sqrt{x}}$ by only subtracting and dividing by two??
Our goal in this section is to understand why this works: \par
How does Quake approximate $\frac{1}{\sqrt{x}}$ by simply subtracting and dividing by two??
\problem{}
Using basic log rules, rewrite $\log_2(1 / \sqrt{x})$ in terms of $\log_2(x)$.