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

Floating Point Numbers - Computerphile

18323 ratings | 885744 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 (799)
Linkin Pаrk (3 days 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 (4 days 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 (6 days ago)
Great teacher.
salman bukhari (12 days ago)
This is beauty. Well presented and many thanks.
MathWorlds (26 days ago)
ah! english speaking world writes their 7s in a weird way... argh
Konstantin Khitrin (3 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 (4 months ago)
It would be good if you can share ways to overcome such errors!!!
Textras (4 months ago)
It's elementary, my dear watson.
Brammuda Depe (4 months ago)
now i know
Mayoman7 (5 months ago)
Ah, but you didn't even touch on the pure magic that is IEEE 754.
heyyy (5 months ago)
But how do normal calculators dont make these miscalculations?
DJ Saint-Hubert (5 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 (5 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.
Дима (5 months ago)
If it is cut, then why it is 0.30...01, and not 0.29...99?
donttouchmeim steril (5 months ago)
I literally just finished working on standard form
Paul Potter (5 months ago)
Nicely explained
oogrooq (5 months ago)
I'm a computer. I'm a computery guy. Everything's made up of buttons and wires...
p Hs (6 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 (6 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 (6 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 (6 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 (6 months ago)
+Computerphile It is 52 in 64bit
Adam Destructor Jr. (6 months ago)
He sounds so frustrated at some points in this video.
Peter Pann (6 months ago)
Endless printing paper... cool notepad...
Eric Wu (7 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 (7 months ago)
This was very helpful, thank you.
Matt Fellenz (8 months ago)
??? Zero point 3
Devin Greenfield (8 months ago)
you make so much more sense than my numerical methods prof, Thank you!
Mister Hat (8 months 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 (9 months ago)
so interesting to listen to!
connor horman (9 months ago)
(Somewhat) Of a save is java's strictfp, but even that sucks. java.math.BigDecimals do exist though.
sogerc1 (9 months 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 (9 months ago)
floating points are base-2 scientific notations... wow
Amaquieria (9 months 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 (9 months ago)
why cant computers round??
Elliott Smith (9 months 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 (10 months ago)
4:09 I think every mathematician died a little inside when you said "all the way to infinity".
Lt Cameron (10 months 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 (10 months ago)
Are you Not gonna recycle those papers?
_ (10 months 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
saneman100 (10 months ago)
Whenever I run into a problem with floating point, its always when I do large tasks that the rounding error gets out of hand and I start getting wrong answers. Other than that, floating point is perfectly fine.
bigdodgybob (10 months ago)
Great explanation
Raj Harsh (10 months ago)
0:32 Makes no sense.
Wild Bore (10 months ago)
I tried it and for me it returned 0.3000000000000004.
Quin K (10 months 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 (10 months 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.
Марина Козак (10 months ago)
omg, he is so passionate about numbers)) But the explanation is great, thanks.
Claude Martin (11 months 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 (11 months 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 (11 months ago)
hudredths, thousandths.. oh my tongue
Riley Stokes (11 months ago)
Nice video, very well explained.
Marcel Robitaille (11 months ago)
That's why you use int if you can (his currency example is good) and never use == to compare floats.
Jordan Holleman (11 months ago)
2:02 just your everyday use of the speed of light
Philippe Nachtergal (11 months 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 (11 months 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)
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 (1 year ago)
how many significant figures can you store if you have a number that has 1 byte of memory.
Wilson Lau (1 year ago)
Your voice is really nice. Btw this is a good video!
Shandy Sulen (1 year ago)
shouts out to my undergrad for teaching me all of this and making me feel like I know something
Arvid Nybrant (1 year ago)
Great video!
cpt nordbart (1 year ago)
wasn't there a Pentium processor with significant errors in floating point calculation?
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
SWGINSPECTOR (2 years ago)
That was good.
TheyZebra (2 years ago)
Awesome as usual! Thanks for the knowledge. Subscribed.
rccarmadben (2 years ago)
i dont understand recursion and i still dont understand thiss
Samuel Prevost (2 years ago)
What a brilliant video, thank you, I wasn't aware of this problem and I'll think about it next time I deal with things like currency etc ^^
Seth Apex (2 years ago)
Why is the power of a computer typically measured in FLOPS?
Nova Valentin (2 years ago)
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.
Luis de Lago (2 years ago)
... but how does the calculator make 0.1 + 0.2 equal 0.3 ... it's a computer after all ... oh and by the way ... pen and paper are discrete tools too and therefore it must be possible for the computer to compute with real real numbers, if it is possible for us using these discrete tools.
MrMine2000 (2 years ago)
I know this error Form javascript
Linggeas Krishnan (2 years ago)
noot noot
Creme De La Meme (2 years ago)
0:53 awww no! you've got it all wrong The speed of light(c) is 299,792,458m/s and yes, i did spend 10 minutes repeating that to memorize it.

Would you like to comment?

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