In the note on Logarithm Approximation Precision note from ABDK many of the magic numbers and numbers of iterations for log2 precision in the Uniswap V3 TickMath Library are defined.

In our case we want to generalize these calculations to give a bit more freedom to implement our own version of the TickLibrary.

Starting with choosing the right $i$ (fine ticks), their is a table that defines the two magic numbers below.

        int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
        int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

The $\text{max } \epsilon$ is subtracted from log_sqrt10001 to get tickLow and the $\text{min } \epsilon$ is added to the TickHi.

Some important equations from ABDK writeup:

$$ \varepsilon_{i+1}(x) = l_{i+1}(x) - \log_2x \in \left( -2^{-(i+1)} + 3(1-2^{-(i+1)})\log_2(1-2^{-127}); +0 \right] $$

$$ l_{i+1}(x) = \left\lfloor \log_2 x \right\rfloor + \frac{1}{2} l_i \left(\left\lfloor\left(\left\lfloor\frac{x}{2^{\left\lfloor \log_2 x \right\rfloor}}\right\rfloor_{2^{-127}}\right)^2\right\rfloor_{2^{-127}}\right) $$

For some base $b$ such that $\psi > \frac{1}{\log_2 b}$ for some $\xi$ we have $\log_{b} \thickapprox \psi \cdot l_{i}(x)$ our error can be defined as

$$ \begin{align*} \psi \cdot l_i (x) - \log_{b} x &= \psi \cdot \left(\log_2 x + \varepsilon_i (x)\right) - \frac{\log_2 x}{\log_2 b} \\ &= \log_2 x\left(\psi - \frac{1}{\log_2 b}\right) + \psi \cdot \varepsilon_i (x) \end{align*} $$

for $x \in [2^{-n}, 2^{n})$ the approximation error is within the following range:

$$ \begin{align*}

&\left(-n\left(\psi - \frac{1}{\log_2 b}\right) + \psi \cdot \left(-\,2^{-i} + 3\left(1-2^{-i}\right)\log_2\left(1 - 2^{-127}\right)\right); \\

n\left(\psi - \frac{1}{\log_2 b}\right)\right) \end{align*} $$

Let $\gamma(x) \in [1 - \delta, 1 + \delta]$, we approximate the inverse function $getRatioAtTick^{-1}(x)$ as:

$$ \log_{b} x - \log_{b} \gamma(y) \approx \psi \cdot l_i (x) $$

and the absolute error of such approximation is:

$$ \psi \cdot l_i (x) - \log_{b} x + \log_{b} \gamma(y) $$

for $x \in [2^{-n}, 2^{n})$ the approximation error is within the following range:

$$ \left(-n\left(\psi - \frac{1}{\log_2 b}\right) +\psi \cdot \left(-\,2^{-i} + 3\left(1-2^{-i}\right)\log_2\left(1 - 2^{-127}\right)\right) +\log_{b} (1-\delta); \\ n\left(\psi - \frac{1}{\log_2 b}\right) + \log_{b} (1+\delta)\right) $$