text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
made this actual software, decided
that the maximum number of coins | 4,138.979 | 3.645 |
the user can accumulate
is, indeed, 4 billion, | 4,142.624 | 1.916 |
because they chose in their code
to use not a long long, apparently, | 4,144.54 | 7.529 |
but just an integer, an unsigned
integer, only a positive integer, whose | 4,152.069 | 4.071 |
max value is roughly that. | 4,156.14 | 1.949 |
Well, here's another funny one. | 4,158.089 | 1.291 |
So in the game Civilization, which
some of you might be familiar, with | 4,159.38 | 4.12 |
it turns out that years ago there
was a bug in this game whereby | 4,163.5 | 3.16 |
if you played the role
of Gandhi in the game, | 4,166.66 | 2.09 |
instead of him being very pacifist,
instead was incredibly, incredibly | 4,168.75 | 5.27 |
aggressive, in some circumstances. | 4,174.02 | 2.379 |
In particular, the way that Civilization
works is that if you, the player, | 4,176.399 | 4.13 |
adopt democracy, your
aggressiveness score gets | 4,180.529 | 4.151 |
decremented by two, so minus
minus, and then minus minus. | 4,184.68 | 3.45 |
>> So you subtract 2 from
your actual iterating. | 4,188.13 | 2.439 |
Unfortunately, if your iterating is
initially 1, and you subtract 2 from it | 4,190.569 | 6.081 |
after adopting democracy
as Gandhi here might | 4,196.65 | 2.4 |
have done, because he was very passive--
1 on the scale of aggressiveness. | 4,199.05 | 3.15 |
But if he adopts democracy, then
he goes from 1 to negative 1. | 4,202.2 | 2.63 |
>> Unfortunately, they were
using unsigned numbers, | 4,204.83 | 6.64 |
which means they treated even negative
numbers as though they were positive. | 4,211.47 | 3.93 |
And it turns out that the
positive equivalent of negative 1, | 4,215.4 | 4.38 |
in typical computer programs, is 255. | 4,219.78 | 3.7 |
So if Gandhi adopts
democracy, and therefore has | 4,223.48 | 3.77 |
his aggressiveness score decreased,
it actually rolls around to 255 | 4,227.25 | 5.22 |
and makes him the most
aggressive character in the game. | 4,232.47 | 3 |
So you can Google up on this. | 4,235.47 | 1.46 |
And it was, indeed, an
accidental programming bug, | 4,236.93 | 2.45 |
but that's entered quite
the lore ever since. | 4,239.38 | 3.63 |
>> That's all fun and cute. | 4,243.01 | 1.35 |
More frightening is when actual
real world devices, and not games, | 4,244.36 | 3.4 |
have these same bugs. | 4,247.76 | 1.06 |
In fact, just a year ago an article came
out about the Boeing 787 Dreamliner. | 4,248.82 | 5.68 |
>> And the article at first
glance reads a little arcane. | 4,254.5 | 2.35 |
But it said this, a software
vulnerability in Boeing's | 4,256.85 | 4.63 |
new 787 Dreamliner jet has
the potential to cause pilots | 4,261.48 | 3.31 |
to lose control of
the aircraft, possibly | 4,264.79 | 2.43 |
in mid-flight, the FAA officials
warned airlines recently. | 4,267.22 | 4.53 |
It was the determination
that a model 787 | 4,271.75 | 2.77 |
airplane that has been powered
continuously for 248 days | 4,274.52 | 5.25 |
can lose all alternating current, AC,
electrical power due to the generator | 4,279.77 | 5.11 |
control units, GCUs, simultaneously
going into fail safe mode. | 4,284.88 | 4.012 |
It's kind of losing me. | 4,288.892 | 0.958 |
But the memo stated, OK, now I got that,
the condition was caused by a software | 4,289.85 | 5.54 |
counter internal to
the generator control | 4,295.39 | 3.2 |
units that will overflow after
248 days of continuous power. | 4,298.59 | 6.27 |
We are issuing this
notice to prevent loss | 4,304.86 | 2.21 |
of all AC electrical
power, which could result | 4,307.07 | 2.23 |
in loss of control of the airplane. | 4,309.3 | 1.68 |
>> So, literally, there is some integer,
or some equivalent data type, | 4,310.98 | 4.4 |
being used in software
in an actual airplane | 4,315.38 | 2.58 |
that if you keep your airplane
on long enough, which apparently | 4,317.96 | 2.796 |
can be the case if you're just running
them constantly and never unplugging | 4,320.756 | 3.124 |
your airplane, it seems, or
letting its batteries die, | 4,323.88 | 2.93 |
will eventually count up, and up,
and up, and up, and up, and up. | 4,326.81 | 3.03 |
>> And, by nature, a
finite amount of memory | 4,329.84 | 2.31 |
will overflow, rolling back to
zero or some negative value, | 4,332.15 | 3.73 |
a side effect of which is the
frighteningly real reality | 4,335.88 | 4.04 |
that the plane might need
to be rebooted, effectively, | 4,339.92 | 4.05 |
or might fall, worse, as it flies. | 4,343.97 | 3.32 |
So these kinds of issues
are still with us, | 4,347.29 | 1.94 |
even-- this was a 2015 article,
all the more frightening | 4,349.23 | 3.9 |
when you don't necessarily
understand, appreciate, or anticipate | 4,353.13 | 2.97 |
those kinds of errors. | 4,356.1 | 2.54 |
>> So it turns out there's one other
bad thing about data representation. | 4,358.64 | 3.39 |
It turns out that even floats are
kind of flawed, because floats, too, | 4,362.03 | 5.05 |
I proposed are 32 bits, or
maybe 64 if you use a double. | 4,367.08 | 4.36 |
But that's still finite. | 4,371.44 | 1.63 |
>> And the catch is that if you can
put an infinite number of numbers | 4,373.07 | 4 |
after the decimal point,
there is no way you | 4,377.07 | 2.39 |
can represent all the possible
numbers that we were taught | 4,379.46 | 3.23 |
in grade school can exist in the world. | 4,382.69 | 2.3 |
A computer, essentially, has to
choose a subset of those numbers | 4,384.99 | 3.88 |
to represent accurately. | 4,388.87 | 1.33 |
>> Now, the computer can
round maybe a little bit, | 4,390.2 | 2.25 |
and can allow you to roughly store
any number you might possibly want. | 4,392.45 | 5.45 |
But just intuitively, if you
have a finite number of bits, | 4,397.9 | 3.04 |
you can only permute them
in so many finite ways. | 4,400.94 | 3.62 |
So you can't possibly
use a finite number | 4,404.56 | 2.01 |
of permutation of bits,
patterns of zeros and ones, | 4,406.57 | 3.31 |
to represent an infinite
number of numbers, | 4,409.88 | 3.06 |
which suggests that computers might
very well be lying to us sometimes. | 4,412.94 | 4.43 |
>> In fact, let's do this. | 4,417.37 | 1.4 |
Let me go back into CS50 IDE. | 4,418.77 | 2.469 |
Let me go ahead and
create a little program | 4,421.239 | 1.791 |
called Imprecision, to show that
computers are, indeed, imprecise. | 4,423.03 | 4.91 |
>> And let me go ahead and start with
some of that code from before, | 4,427.94 | 3.97 |
and now just do the following. | 4,431.91 | 1.92 |
Let me go ahead and do printf, percent
f, backslash n, 1 divided by 10. | 4,433.83 | 9.81 |
In other words, let's dive in deeper
to 1/10, like 1 and divided by 10. | 4,443.64 | 3.79 |
Surely, a computer can represent 1/10. | 4,447.43 | 2.33 |
>> So let's go ahead and make imprecision. | 4,449.76 | 3.86 |
Let's see. | 4,453.62 | 0.77 |
Format specifies type double. | 4,454.39 | 1.82 |
But the argument has type int. | 4,456.21 | 1.95 |
What's going on? | 4,458.16 | 0.88 |
>> Oh, interesting, so it's a
lesson learned from before. | 4,459.04 | 2.93 |
I'm saying, hey, computer show
me a float with percent f. | 4,461.97 | 4.08 |
But I'm giving it 2 ints. | 4,466.05 | 2.15 |
So it turns out, I can fix
this in a couple of ways. | 4,468.2 | 2.92 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.