Live data from Hacker News

1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

wolframalpha.com

31–40 of 109 posts

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#31
post #24

Pretty cool. Can we use WolframAlpha to show why 0.1 cannot be represented as a floating binary? And why floating numbers shouldn't be used for currency operations.

Yes.

http://www.wolframalpha.com/input/?i=1%2F10+in+base+2

TL;DR: 1/10 has an infinite repeating binary expansion. (think 1/3 in decimal - 0.3333333) The part that really gets you into trouble is that the repeating pattern is 0011, which means it rounds differently depending on how many digits of precision you give it.

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#33
As people have pointed out:

1/98 = 0.01 02 04 08 16 32 ...

1/998 = 0.001 002 004 008 016 032 064 128 256 ...

but there's also a degenerate case, where you have no 9s at all:

1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ...

and what's surprising here is that everything adds up and gives you the terminating decimal 0.125 that you were expecting.

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#34

As people have pointed out: 1/98 = 0.01 02 04 08 16 32 ... 1/998 = 0.001 002 004 008 016 032 064 128 256 ... but there's also a degenerate case, where you have no 9s at all: 1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ... and what's surprising here is that everything adds up and gives you the terminating decimal 0.125 that you were expecting.

> 1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ...

The sum of a convergent series is a / (1 - r) where a is the first value, and r is the ratio between the n+1th and nth term.

    a = 1/10, r = 1/5

    n = (1 / 10) / (1 - (1 / 5))
    n = (1 / 10) / (4 / 5)
    n = 5 / 40
    n = 1 / 8

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#38

I gotta be that guy: Why is this the first post on the front page of Hacker News? Is basic arithmetic really so fascinating to the computer people?

I hope you can see why this example of basic arithmetic is really neat. It reminds us that there are hidden patterns everywhere. Oftentimes, we can determine why the pattern exists with math.

It never hurts to be reminded how cool it is to learn.

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#39

The pattern will break down once you get past 8192, which is 2^13. That means that the pattern continues for an impressive 52 significant figures (well, it actually breaks down on the 52nd digit, which will be a 3 instead of a 2). The reason it works is that 9998 = 10^4 - 2. You can expand as 1 / (10^n - 2) = 1/10^n * 1/(1 - 2/10^n) = 1/10^n * (1 + 2/10^n + 2^2 /10^2n + 2^3 /10^3n + ...) which gives the observed patt…

[deleted]

Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..

#40

As people have pointed out: 1/98 = 0.01 02 04 08 16 32 ... 1/998 = 0.001 002 004 008 016 032 064 128 256 ... but there's also a degenerate case, where you have no 9s at all: 1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ... and what's surprising here is that everything adds up and gives you the terminating decimal 0.125 that you were expecting.

> 1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ... The sum of a convergent series is a / (1 - r) where a is the first value, and r is the ratio between the n+1th and nth term. a = 1/10, r = 1/5 n = (1 / 10) / (1 - (1 / 5)) n = (1 / 10) / (4 / 5) n = 5 / 40 n = 1 / 8

I knew that. I left it as an exercise for the commenter.
Post reply on HN