Floating Point Numbers - Computerphile

preview_player
Показать описание
Why can't floating point do money? It's a brilliant solution for speed of calculations in the computer, but how and why does moving the decimal point (well, in this case binary or radix point) help and how does it get currency so wrong?

This video was filmed and edited by Sean Riley.

Рекомендации по теме
Комментарии
Автор

I think this actually used to be a flaw in some banking systems, because programmers initially used floating-point numbers to store accounts money. And then someone took advantage of it by making a lot of transactions from 2 of his accounts, where each transaction made him win a tiny bit of money due to rounding. So in the long term he was able to "create" as much money as he wanted.

timothemalahieude
Автор

Everything is easier to understand if it's explained in british accent

InsaneMetalSoldier
Автор

Explains weird results I got in BASIC programs years ago!

MorreskiBear
Автор

I got 0.9999... Problems and floating point is one.

Daealis
Автор

This is why Minecraft 1.7.3 alpha has block errors after 2 million blocks away from spawn. Pretty cool.

MMMowman
Автор

Small correction: You don't need a 64-bit computer to use 64-bit floating point numbers in hardware. For example on Intel processors 64-bit floating point has been supported since at least the 8087, which was a math co-processor for the 16-bit 8086 CPU. (The math co-processor has been integrated into the main CPU since the 80486, which was a 32-bit processor.)

DjVortex-w
Автор

Another issue I've run across with floating point rounding errors is the fact that - for the same reasons outlined in the video - a comparative statement like "0.1 + 0.2 == 0.3" comes out false, and it can be super annoying to pick out where the error is coming from, especially if it's buried in some if statement. For things like currencies, I usually just deal with ints that represent the number of cents (e.g. $2.50 is represented as 250), and divide by 100 in the end... saves me the hair tearing.

oatstralia
Автор

Minecraft stores entities as floating point's, when the world was infinite you could teleport something like 30, 000km in any direction and see objects start to move and stutter about including the player.
Once you hit 32 bit int overflow the world would become Swiss Cheese, and at the 64 bit int overflow, the world would collapse and crash.

Creaform
Автор

nought (nɔːt)
(Mathematics) the digit 0; zero: used esp in counting or numbering

For those who were wondering. I guess it has the advantage of being half the number of syllables as "zero".

antivanti
Автор

I remember the first time I experienced this. I was writing a Pac-Man clone, and I set Pac-Man's speed to be 0.2, where 1.0 would be the distance from one dot to another. Everything worked fine until I started coding the wall collisions, where Pac-Man keeps going straight ahead until hitting a wall, causing him to stop. The code checked to see if Pac-Man's location was a whole integer value, like 3.0, and if it was it would figure out if a wall had been hit. When I tested it, though, Pac-Man went straight through the walls. If I changed the speed to 0.25, though, it worked exactly as expected. I was baffled for a few moments, and then it hit me. Computers don't store decimal values the way you might first expect.

wolverine
Автор

american here, just hearing 'Not Not Not Not Not Not Not Not Not Not Not seven'

AtheniCuber
Автор

Do you remember the (in)famous Apple IIe 2 squared error? 2+2 yielded four, as it should have been, but 2^2 yielded somothing like and floating point arithmetic was difficult on 8 bit computers anyway. I once even used a character array to emulate fifteen digits behind the comma, not anything I'd do nowadays, but it worked then.

eisikater
Автор

Can you PLEASE do more with Tom Scott? He's awesome!

themodernshoe
Автор

An even better example of floating point error is trying to add 1/5 and 4/5 in binary, which is similar to the example in the video about adding thirds:
1/5 = 0.0011~
4/5 = 0.1100~
1/5 + 4/5 = 0.1111~

joemaffei
Автор

I have a computer science degree from a top school, and yet nothing was ever explained nearly as well as this.

I love this YouTube channel. Absolutely brilliant explaination. Thank you!!

mtveltri
Автор

This is great, I've finally understood what it means (and why) when people say "loses precision" when referring to floating points.

kagi
Автор

I've put up English closed captions for this, since I haven't seen anyone else do CCs for this video, which is weird.

I think it still needs authorised before it shows up actually on the channel, though.

novarren
Автор

starting out programming and some bullshit turned out as instead of 4 so i'm here now xD

junofall
Автор

I appreciate the fact that you get into the topic right at the first second. You don't see this in the world very often.

paterfamiliasgeminusiv
Автор

Well I've been working with computers for some 35 years and while very early compilers used to do 32 bit FP (floating point) around 20 years ago some people got together and settled on standards for floating point on computers and soon after 80 bit FP became a standard even though the computers were only 16 or 32bit at the time. Basically the machine's register size (32bit etc. has nothing to do with the number size usable as a sub-program deals with it. Sure it won't be as time efficient, but that's not what was suggested here.

etmax