It got me thinking about one of my t-shirts. I have a t-shirt with the statement that “2+2=5 for extremely large values of 2”. This is of course from George Orwell’s book: 1984, however it is just as true as ever. Wait, what? True?
Bear with me.
2 is a number.
A slightly different
2 would be
So an “extremely large value of 2” would be something like
You pronounce it “two point six”, but still “two”.
Two of these added together,
2.6 + 2.6 would then in turn make
Another way of looking at the
2+2=5 “problem” is with Ruby.
Let me make you a script, which will print it out:
and voilà, there you have it
2 + 2 = 5.
Of course I’m just fooling around. However, there are some quirks to be had from this. Don’t trust numbers! They might tell you that they are something, they are not.
The result here is:
0.1 + 0.2 = 0.30000000000000004.
First lets look at fractions.
1/10 is of course
0.2 and so on.
We can also do
1/2 which is
Well, the closest we can get to it is
0.33... with an infinite string of
However, like with the Numberphile video, if we ever stop putting in
3s, we will be off of the correct result.
0.3 is the same.
0.3 in binary is
0.10011001100... with an infinite loop of
If we had infinite precision we would be able to correctly write out the number, however, in computers we do not have infinite precision, but are limited to some finite precision, which is why the addition of
0.2 doesn’t yield
0.3, but rather something fairly close.
Let’s try something fun.
This will actually return
Both of these problems can be combated using Ruby’s BigDecimal class, which are not limited by the precision of the computer in the same way. Here we can get the correct result for both problems: