I am studying Numerical Analysis.
In the beginning of the book they go through a method of converting base 10 decimals to base $2$. Multiply the decimal number $a<1$ with $2$, the whole part ($0$ or $1$) will be your bit at $2^{-1}$ and repeat the process with the fraction. $$0.4\cdot 2=0.8+0$$ $$0.8\cdot 2=0.6+1$$ $$0.6\cdot 2=0.2+1$$ and so on.
One of the exercises I am struggling with is this:
Find the first 15 bits of the binary representation of $\pi$ and $e$.
Through Taylor series we know that
$$\frac{\pi}{4} = 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}...$$ $$e = 1+1+\frac{1}{2!}+\frac{1}{3!}...$$
My simplest solution: $\pi\approx 3.14159=3+0.14159$ since we need $2$ bits to represent the whole number, we have $13$ bits to represent the fraction.
We are going to cut off the infinite series of decimals at some point and convert that finite decimal number to binary. This will cause two rounding error.
- The binary representation of our cut of decimal number is not going to be exact and we need to calculate the biggest error possible.
- The error caused by the discarded sequence of decimals and we need to calculate the biggest error.
After this we add the two errors and it should be less than the lowest representable binary number with $13$ bits. $2^{-13}>0.00012$
The biggest error for both $1$. and $2$. is a infinite binary sequence of 1s. If we add the two errors and assume they are $(0.1111...)_2\cdot 2^{-15}$ together we get an error of the size $(1.1111...)_2\cdot 2^{-14}$. That is biggest error we can have without affecting the bit at position $2^{-13}$ and thus we should have the correct bits in our representation.
$2^{-15}\approx 0.0000305$ is the highest error we can accept. $0.14159$ is therefore within our acceptable range since a never ending sequence of nines follow our last digit could only produce an max error of $0.00001$.
To approximate a binary representation of $0.14159$ we need to use $2^{-15}$ as our last bit to ensure the error is small enough. $$0.14159\cdot 2= 0.28318 + 0$$ $$0.28318\cdot 2= 0.56636 + 0$$ $$0.56636\cdot 2= 0.13272 + 1$$ $$0.26544+0$$ $$0.53088+0$$ $$0.06176+1$$ $$0.12352+0$$ $$0.24704+0$$ $$0.49408+0$$ $$0.98816+0$$ $$0.97632+1$$ $$0.95264+1$$ $$0.90528+1$$ $$0.81056+1$$ $$0.62112+1$$
$$0.62112\cdot 2^{-15}<2^{-15}$$
Therefor our representation of $\pi$ is $11.0010010000111$
My question is if my reasoning is correct, especially regarding the error handling, and if there is any easier method?