Computing The Precision

Posted by Beetle B. on Wed 20 March 2019

To get \(p\) of the floating point system you are on:

i = 0
A = 1.0
B = 2    # The radix.
while (A + 1.0) - A == 1.0:
    A = B * A
    i += 1
print(i)

Why does this work? A starts off as 1.0. Now the condition holds true as long as the ulp is 1. When we multiply by \(\beta\), we are shifting its position in \(M\). So initially \(M=00001\). Then it becomes \(M=00010\) (in whatever base we are dealing with). Once we have \(M=10000\), then the next multiplication will make the ulp be \(\beta>1\), and the condition will no longer hold true.