(I ask this on math.se but was advised to come over here... Go easy on me, I am not a CS person.)
I am learning to program and came across the interesting byproduct of computer number representation shown by
0.1 + 0.2 = 0.30000000000000004
In trying to understand why this occurs, one has to understand how 0.1 is stored on the computer. I worked out that
0.1(10) = 0.00011001100...(2)
and subsequently read that the number floating-point numbers closest to 0.1 are
0.09999999999999999167332731531132594682276248931884765625
and
0.1000000000000000055511151231257827021181583404541015625
(source: https://stackoverflow.com/a/27030789).
Curious as to how to actually determine these number(s), I attempted to write a python script to find them and failed miserably.
I then turned to google and found this answer to a similar question: https://math.stackexchange.com/a/2119191/22276. I was able to follow the solution completely in my case until the portion computing the numbers 14411518807585587 and 14411518807585588. How do I use these numbers to get the two surrounding numbers.
For reference, my two integers would be determined by:
2-4=.0625 <= 0.1 < .125 = 2-3
causing e = -4. I then compute the integer part of
0.1 * 253-(-4) which is
144 115 188 075 855 872
This is where I am stuck. Could someone walk me through this with the impression your audience is CS-illiterate?