HomeОбразованиеRelated VideosMore From: Computerphile

Floating Point Numbers - Computerphile

20151 ratings | 965797 views
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? 3D Graphics Playlist: http://www.youtube.com/playlist?list=PLzH6n4zXuckrPkEUK5iMQrQyvj9Z6WCrm The Trouble with Timezones: http://youtu.be/-5wpm-gesOY More from Tom Scott: http://www.youtube.com/user/enyay and https://twitter.com/tomscott http://www.facebook.com/computerphile https://twitter.com/computer_phile This video was filmed and edited by Sean Riley. Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: http://bit.ly/bradychannels
Html code for embedding videos on your blog
Text Comments (879)
Ilan Goldenberg (10 days ago)
"floating point numbers" response: 5:52
Aaron Risley (10 days ago)
This is me when I tried mushrooms
Acorn (19 days ago)
Just use bignum.
Patrick Philippy (23 days ago)
Just do all your maths in hexadecimal. Easy
Jesse Baldwin (1 month ago)
I feel like I'm pumping gas in america
LuaConstructor (1 month ago)
um... we use 64 bit now
Wai Shing Tseung (1 month ago)
(0.333…)3=0.999…
Krishna Sivakumar (1 month ago)
I'm loving this channel. It's heaven.
Kevin Portillo (1 month ago)
I miss school :( *college that is* lol
Jacob Passam (2 months ago)
Ain’t this called standard form?
Theta (2 months ago)
Sorry to comment on a video from 4 years ago, but why don't modern compilers suffer from this anymore? For example, adding 0.20 and 0.10 in Visual Studio gives you 0.30 (0.3). Doesn't this mean the rounding point error has been removed?
dimitar unknown (3 months ago)
How I deal with this is I write numbers in a string, then explode that and make an array of character and cast each to an int, then I do the calculation and return it in a float format. It literally has never failed me...
Aaron Braskin (3 months ago)
After all that I just have one last question. Where did he get that old school feed paper? (It makes awesome note paper!)
Woody Woodlstein (3 months ago)
Great teacher.
salman bukhari (3 months ago)
This is beauty. Well presented and many thanks.
MathWorlds (3 months ago)
ah! english speaking world writes their 7s in a weird way... argh
Konstantin Khitrin (6 months ago)
That "1MB per number" is entirely nonsensical. 256 bits fixed precision numbers are already total overkill in dealing both with subatomic scales and size of the universe, and we have registers that can hold one of these on modern CPUs. Sure, back in the day, the difference between 256 bits and 32 bits per number was crucial, but today, it's a convenience thing, nothing more.
Ganesh D (7 months ago)
It would be good if you can share ways to overcome such errors!!!
Textras (7 months ago)
It's elementary, my dear watson.
Brammuda Depe (7 months ago)
now i know
Mayoman7 (8 months ago)
Ah, but you didn't even touch on the pure magic that is IEEE 754.
heyyy (8 months ago)
But how do normal calculators dont make these miscalculations?
DJ Saint-Hubert (8 months ago)
things about the human condition should be expressed as floating point, not boolean btw
If computers cannot also accurately process floating numbers does it not say a lot about the characteristics of floating numbers? :)
Walter5850 (8 months ago)
These rounding errors are quite obvious in systems that are highly sensitive on initial conditions (chaotic systems). Basically to the point where if you run absolutely the same program on a 32 bit cpu vs a 64 bit cpu, you will soon get completely different results. For example calculating a double joint pendulum swing.
Дима (8 months ago)
If it is cut, then why it is 0.30...01, and not 0.29...99?
donttouchmeim steril (8 months ago)
I literally just finished working on standard form
Paul Potter (8 months ago)
Nicely explained
oogrooq (9 months ago)
I'm a computer. I'm a computery guy. Everything's made up of buttons and wires...
p Hs (9 months ago)
Can you tell how much space it would take to store a .txt file which has a Googolplex written digit by digit. Like realistically,
OnoxOrion (9 months ago)
The entire set of complex algebraics are countable and arithmetic should still be polynomial time, so I don't get why errors are excusable.
Commenting Account (9 months ago)
Sorry, but I have to say it: for whatever reason, I think this guy wouldn't look very out-of-place in colonial America.
DeRepear (9 months ago)
JavaScript is a big culprit of this sort of thing, many other languages like Python will automatically know that 0.1 + 0.2 = 0.3 but JavaScript won't automatically (try typing it in your browser's developer console). It does have built in functions to help with this sort of thing though.
Avi Seth (9 months ago)
+Computerphile It is 52 in 64bit
Adam Destructor Jr. (9 months ago)
He sounds so frustrated at some points in this video.
Peter Pann (9 months ago)
Endless printing paper... cool notepad...
Eric Wu (10 months ago)
Wow. I remember this from my early times in programming. Now I am learning programming in school and those programming languages are so smart that they fix these errors for us. It makes me kind of sad to think that in the future these things will be done for us, and an understanding of these sort of things is going to be obsolete.
Lee Annison (10 months ago)
This was very helpful, thank you.
Matt Fellenz (11 months ago)
??? Zero point 3
Devin Greenfield (11 months ago)
you make so much more sense than my numerical methods prof, Thank you!
Mister Hat (1 year ago)
Floating point is quick on some processors. On any processor without dedicated hardware it's MUCH slower than 2's complement integer math.
Alina Podryhun (1 year ago)
so interesting to listen to!
connor horman (1 year ago)
(Somewhat) Of a save is java's strictfp, but even that sucks. java.math.BigDecimals do exist though.
sogerc1 (1 year ago)
goddamn it, I've never seen this case before: perl -le 'print 1/10+2/10==3/10?"yes":"no"' indeed prints *no* great, one more thing to worry about.
Cambesa (1 year ago)
floating points are base-2 scientific notations... wow
Amaquieria (1 year ago)
When working with an assembly program my teacher wanted me to initialize all my floating point variables to 0....for some reason it never worked.
Alaric (1 year ago)
why cant computers round??
Elliott Smith (1 year ago)
I think that he missed the major oversight that people have with floating point numbers: We're representing a *continuous* set of real numbers by a *discrete* set of floating numbers.
Insanity Cubed (1 year ago)
4:09 I think every mathematician died a little inside when you said "all the way to infinity".
Lt Cameron (1 year ago)
Great video. Very many thanks. Makes floating point so much easier to understand.Bonus that it's a young brit! Well done.
Seth Tan (1 year ago)
Are you Not gonna recycle those papers?
_ (1 year ago)
1:55 You're wrong. The speed of light is EXACTLY 300000000m/s, because this is how meters are defined.
this channel is interesting
bigdodgybob (1 year ago)
Great explanation
Raj Harsh (1 year ago)
0:32 Makes no sense.
Wild Bore (1 year ago)
I tried it and for me it returned 0.3000000000000004.
Quin K (1 year ago)
you know what annoys me about this? in america we say math... not maths... now i'm really bothered because i'm that one guy who kills someone for not using correct grammar
Rachel Mant (1 year ago)
Would be fantastic to see a video done on Fixed Point, which is the other way to solve the Floating Point accuracy issues for some small length of numbers, especially as you can store the decimal component as an integer and do some clever maths computing the overflow quantity back into the integer component. This is actually how programs like Excel solve the problem when you click the Currency button.
omg, he is so passionate about numbers)) But the explanation is great, thanks.
Claude Martin (1 year ago)
"32 bit computer" -> that's about addressing. They can handle 64 bit floating-point arithmetic. You could build a computer that can do 128 bit floating-point arithmetic and uses only 16 bit for addressing. There certainly is some relation when it comes to CPU design and the floating-point unit size, register size and address size. But it's not really the same. It might even be handled by a coprocessor. And FPU stack registers are usually 80 bits (10 bytes) wide, not 64 bits. See fld, fild, and fbld in assembly.
Double Orts (1 year ago)
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.
Sane Diamond (1 year ago)
hudredths, thousandths.. oh my tongue
Riley Stokes (1 year ago)
Nice video, very well explained.
Marcel Robitaille (1 year ago)
That's why you use int if you can (his currency example is good) and never use == to compare floats.
Jordan Holleman (1 year ago)
2:02 just your everyday use of the speed of light
Philippe Nachtergal (1 year ago)
The problem is of course once you need to compare numbers. Especially for legal stuff related to stupid laws. Suppose you must declare some stuff to the government if the total value is strictly more than 10,000 dublons. When compliance is checked and you find a value of 10,000.0001 is that more than 10,000 or is equal 10,000 give or take imprecision inherent to floating point operations ? And what is precisely your margin ? Is it a static margin or do you make it depends on the operations you had to perform to compute the total ? (Since imprecision is increased when some operations are performed) By the way, it helps to *not* think about it in terms of rounding errors but really in terms of imprecision. Rounding errors are made on top of that... Yes, ultimately they are the same thing, but thinking of them that way doesn't help reasoning. It is easier to understand rounding as the base 10 rounding you do in "real world" and imprecision as "the problem with computer not being able to code numbers perfectly".
Jyotirmay Ghosh (1 year ago)
what a voice man, and thanks a lot all my doubt cleared...
Flarezard (1 year ago)
I'm here because I have an exam tomorrow .-.
Juan Lantigua (1 year ago)
I have a video suggestion, you should count the number of integers points in a 2D triangle. Tough algorithmic challenge
Ben Christensen (1 year ago)
So good!!
Andreas Thehos (1 year ago)
Thanks a lot for your explanation! Floating Point Numbers are a very big problem in spreadsheet calculations most People are not aware of. If you do a lookup or if-function the normal user expects, that his numbers are correct and not smaller or bigger. I allways use to round a value to cut the error off.
wolverine96 (1 year ago)
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.
RGBPlaza (1 year ago)
So the pound is going down in value because we're generating of fractions of pennies left right and centre!
thejking (1 year ago)
Excellent video!
Frans van den Berg (1 year ago)
He didn't address the hidden Guard and Round bit in the floating point arithmetic unit processor.
dick tater (1 year ago)
is this why the frame rate in the US is 29.97 and not 25?
J L (1 year ago)
7m in, "... because to *its* mind..." - Hmmm? Computers have minds?
lucaz z (1 year ago)
It's literally just a rounding error from the computers end, btw I'm curious how calculators deal with this problem, for example if you did root two squared you should get 2, but of course the calculator can't know this cause it doesn't understand infinite decimal places. I assume they are just programmed with these special cases in mind
TheKazragore (1 year ago)
It's so nice to hear someone say "maths" on YouTube.
viccie211 (1 year ago)
If you ever want to see the failure of precision of a 32 bit float in a video game, go watch kurtjmac's Far Lands or Bust. He has walked so far in minecraft his location on one axis has lost precision to quarters of blocks! Especially episode 471 where he finds the boundary where the precision loss increases.
Samantha Bayley (1 year ago)
This finally explains strange results in a program I wrote for first year uni. The program was meant to calculate change in the fewest possible coins but whenever I had 10c left it would always give two 5c coins, for the life of me I couldn't figure out why now I know. It also used to happen with the train ticket machines so at least I'm not alone in making that error.
Reuben Andrews (1 year ago)
my teacher failed to teach me this with years, tom scott succeded in 10 minutes
Torsopher (1 year ago)
I like how they add a / to <computerphile> to mark the end of the video
HelionDark (1 year ago)
now i get why i get those strange outputs.
Wolf moon (1 year ago)
Very well explained thank you
ATMunn (1 year ago)
After the start of the video, I'm like "Hm, really? That happens? Alright." So I opened up the Python shell (I just started learning Python) and typed in "0.1 + 0.2" and sure enough... It spat out "0.30000000000000004"
Maarten Vorwerk (1 year ago)
This the first time I hear anyone say naught instead of zero
Charlie Green (1 year ago)
why did they call it a floating point number, where does the name come from
Wondering Why (1 year ago)
So that's why my 42.1 became 42.099998
timothylewisthornton (1 year ago)
Let's talk about the lights being on, all of a sudden. That's weird.
Mick Mathers (1 year ago)
fan-fold paper. So retro
azakura1991 (1 year ago)
awesome
maciejasz78 (1 year ago)
Oh come on. 32 bit computers and single precision floating point format are two very different things. We,ve had 32 bit processors with 80 bit precision floating point units for years.
MrBrN197 (2 years ago)
how many significant figures can you store if you have a number that has 1 byte of memory.
Wilson Lau (2 years ago)
Your voice is really nice. Btw this is a good video!
Shandy Sulen (2 years ago)
shouts out to my undergrad for teaching me all of this and making me feel like I know something
Arvid Nybrant (2 years ago)
Great video!
cpt nordbart (2 years ago)
wasn't there a Pentium processor with significant errors in floating point calculation?
Fernando Franco Félix (2 years ago)
Just happened to me, my algorithm didn't worked because I was asking for the place where the vector was =0.8 but it was in fact =0.80000001
Mark Freeman (2 years ago)
Great vid, cheers

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.