# Find precision, or the number of digits in the mantissa, in a floating point machine number

We have that: $$\epsilon$$ is the smallest positive machine number that summed to $$1$$ resuts in $$(\epsilon + 1)$$: i.e. the smallest number greater than $$1$$:

if $$p$$ is precision and $$\beta$$ the base:

$$\begin{array}{lcl} 1 & = & 0.1\underbrace{00 \ldots 00}_{p-1 \text{ zeros}} \times \beta^1 \\ 1 + \epsilon & = & 0.1\underbrace{00 \ldots 0}_{p-2}1 \times \beta^1 \end{array}$$ we can consider $$\epsilon$$ as the distance between the above numbers: $$\begin{array}{lcl} \epsilon & = & (1+\epsilon) - 1 \\ & = & 0.1\underbrace{00 \ldots 0}_{p-2}1 \times \beta^1 - 0.1\underbrace{00 \ldots 00}_{p-1} \times \beta^1 \\ & = & 0.\underbrace{000 \ldots 0}_{p-1}1 \times \beta^1 \\ & = & 1 \times \beta^{1} \times \beta^{-p} \\ & = & 1 \times \beta^{1-p} \\ & = & \beta^{1-p} \end{array}$$

so the only significant figure $$1$$, stays on the p-th position after the dot.
Calculating the value of that $$p$$, is equivalent to know the precision, i.e. the number of digits for the mantissa.

I know that the algorithm for finding Epsilon Machine is similar to this:

U = 1.0
while (1+U)>1 do
Umem = U
U = U/beta
end while
U = Umem


and I know that, from the given $$\epsilon$$, I can calculate the number $$p$$ of digits for the mantissa:

$$\begin{array}{lcl} \epsilon & = & \beta^{1-p} \\ \log\epsilon & = & \log\beta^{1-p} \\ \log\epsilon & = & (1-p)\log\beta \\ p & = & 1-\frac{\log \epsilon}{\log \beta} \end{array}$$

I don't know how elaborate this fact in Python, can you give me any hint? Thanks.