edits
This commit is contained in:
parent
4f4675a164
commit
e92fae453e
@ -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)$.
|
||||
|
Loading…
x
Reference in New Issue
Block a user