Understanding Floating Point Struggles in 7 Minutes or Less

  Рет қаралды 9,643

Engineer Man

Engineer Man

5 ай бұрын

Ever wonder why weird things happen with floating point numbers? In this video I'll go throw why that is.
Decimal to binary video:
• How To Count in Binary...
Hope you enjoyed the video!
Check out some code on my GitHub:
github.com/realtux
github.com/engineer-man/youtube
Other Social:
/ engineerman
/ _engineerman
/ discord

Пікірлер: 37
@johnbarbero757
@johnbarbero757 5 ай бұрын
There are definitely places in computer graphics where floating point errors will become noticeable (texture bleeding, or other weird lines/banding). I also ended up having to rip out float as the underlying datatype for a budgeting application I worked on since the errors were biting me in all kinds of unexpected places. Python has a Decimal type, which worked well for my use case as replacement.
@OddMathisen
@OddMathisen 5 ай бұрын
This is why floating point comparison is usually done with some threshold. I.e. to check if variable A is equal to 0.3, you would compare A-0.3
@ZacKoch
@ZacKoch 5 ай бұрын
Nice work. Coming from a networking background watching you explain how to represent 12 made me want to bang my head on my desk though. 😂 You're not wrong, but the way you explained it is like rocket science from how I've been doing it all my life lol. This may be the first time I can explain something to YOU in an easier way vs the other way around lol. ❤
@darrenphillips1845
@darrenphillips1845 5 ай бұрын
It's a wonder we didn't shoot right past the moon.
@zane812
@zane812 5 ай бұрын
never went
@darrenphillips1845
@darrenphillips1845 5 ай бұрын
@zane812 - When they say we lost the 60s tech that we used to get to the moon, and that's why we haven't gone back, I'd tend to agree with you.
@nitsanbh
@nitsanbh 5 ай бұрын
@@zane812so during the Cold War, Russia joined the US lie (by not publishing the moon landing was faked)? That’s an even bigger conspiracy theory
@Chicken_Soy
@Chicken_Soy 5 ай бұрын
To the moon! 🚀 🌝 Playboi carti 2024 album upcoming
@baileyharrison1030
@baileyharrison1030 5 ай бұрын
@@darrenphillips1845We haven’t lost the tech we’ve lost the motivation and funding. Back then, the space program was 5% of the federal budget, now it’s 0.5%. People were complaining that the government ‘spent too much money on the moon’.
@JohnDoe4321
@JohnDoe4321 5 ай бұрын
One of the consequences of this is that you should avoid doing equality comparisons on floating point numbers. Code like "if (a + b + c == 1.0)" is subject to unexpected failure.
@bertblankenstein3738
@bertblankenstein3738 5 ай бұрын
Exactly! It is OK to use 《 or 》but == should not occur. Perhaps check if a number is within a range as an alternative solution.
@paulm3702
@paulm3702 5 ай бұрын
Great seeing a visual breakdown of the memory and the walkthrough for the problem!
@repairstudio4940
@repairstudio4940 5 ай бұрын
I truly enjoy your videos. When will you do a video about yourself, an intro, how you got started developing? What's your favorite language? A Q&A stream would be cool...🎉
@mechjack
@mechjack 5 ай бұрын
I've seen math programs such as mathcad keep floating point numbers as fractions of whole numbers, i believe to fix this very problem .
@C4rb0neum
@C4rb0neum 5 ай бұрын
Amazing quality video! It’s clear that you have skills
@ndbass09
@ndbass09 5 ай бұрын
Love your videos. Keep it up!
@shadowpenguin3482
@shadowpenguin3482 5 ай бұрын
5:00 I did not get that one. You just explained that the numbers are the same but have different exponents. That means even in binary 0.2 is exactly 2*0.1. So either they are both slightly larger than the decimal number or both slightly smaller.
@alankoester3344
@alankoester3344 5 ай бұрын
Something completely off topic. You had a video a year ago about the end of the Atom text editor. It seems it was revived as Pulsar IDE. Would you be interested in looking at it and report on it?
@nepp9574
@nepp9574 5 ай бұрын
A different technique for converting decimal to binary is starting from the left to see if it fits in your number and then substracting that from your number if it does: 9 1000 ^^^^ 8421 9 - 8 = 1 1001 ^^^^ 8421 1 - 1 = 0 If this makes sense at all. Only requires you to know what the left most bit represents, which is 8 in this case.
@EngineerMan
@EngineerMan 5 ай бұрын
Yes so this was the way I taught it in my binary video in description.
@ecavero1
@ecavero1 5 ай бұрын
0:51 If you use groovysh, 0.1 + 0.2 does give you 0.3, This is because Groovy uses Java's BigDecimal class by default.
@borstenpinsel
@borstenpinsel 5 ай бұрын
Which doesn't rely on floating point precision and uses more memory than a single integer and more cpu time than a simple addition of 2 registers. You can calculate beyond the precision of a 64 bit float. (How else are computers coming up with the 1000th decimal place of Pi). It just uses more memory and flops
@KontrolStyle
@KontrolStyle 5 ай бұрын
we love some engineer man 8)
@PrivateUsername
@PrivateUsername 5 ай бұрын
Maybe add in a bit about ULP? That could help with understanding why you get .30000004 vs .30000012 or whatnot.
@MisterDan
@MisterDan 24 күн бұрын
Very nice video BTW.
@esra_erimez
@esra_erimez 5 ай бұрын
Really good video. If you want a good treatment on floating point, I recommend one of my dad's favorites "Numbers in Theory and Practice" by Blaise W. Liffick. And, if you want a really in depth treatment on the subject, the authoritative source is Knuth's "Art of Computer Programming, The: Seminumerical Algorithms, Volume 2"
@lyshaka
@lyshaka 5 ай бұрын
I just tried it in C just to see the result (which is obviously the same), but the error is definitely greater using simple float rather than double : float precision : float : 0.30000001192092896000 double : 0.30000000000000004000 using that code : #include int main(int argc, char **argv) { float f_res = 0.1 + 0.2; double d_res = 0.1 + 0.2; printf("float precision : "); printf("float : %1.20f ", f_res); printf("double : %1.20f ", d_res); return (0); }
@utekk
@utekk 5 ай бұрын
Thx man
@HadToChangeMyName_YoutubeSucks
@HadToChangeMyName_YoutubeSucks 5 ай бұрын
Well explained. I've never been the first commenter before.
@EngineerMan
@EngineerMan 5 ай бұрын
First time for everything!
@simonmaracine4721
@simonmaracine4721 5 ай бұрын
👍
@OneOfThePetes
@OneOfThePetes 5 ай бұрын
PowerShell 7 returns 0.3
@rebel478
@rebel478 5 ай бұрын
Bro please tell me why is your right eyebrow always higher
@0xDEAD-C0DE
@0xDEAD-C0DE 5 ай бұрын
None of your business man.
@kkd0099
@kkd0099 5 ай бұрын
wtf are u talking about
@ZacKoch
@ZacKoch 5 ай бұрын
It's because he's on sus looking at your comment 😂 - don't be a d!
Why Is This Happening?! Floating Point Approximation
5:46
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 124 М.
КАКОЙ ВАШ ЛЮБИМЫЙ ЦВЕТ?😍 #game #shorts
00:17
ELE QUEBROU A TAÇA DE FUTEBOL
00:45
Matheus Kriwat
Рет қаралды 16 МЛН
1 класс vs 11 класс (неаккуратность)
01:00
Difficult Programming Concepts Explained
11:13
Engineer Man
Рет қаралды 68 М.
Linux processes, init, fork/exec, ps, kill, fg, bg, jobs
13:47
Engineer Man
Рет қаралды 169 М.
The Algorithm Behind Spell Checkers
13:02
b001
Рет қаралды 383 М.
Using My Python Skills To Punish Credit Card Scammers
7:13
Engineer Man
Рет қаралды 4,8 МЛН
computers suck at division (a painful discovery)
5:09
Low Level Learning
Рет қаралды 1,5 МЛН
Engineer Breaks Down Hollywood Programming Scenes
11:02
Engineer Man
Рет қаралды 22 М.
Floating Point Numbers - Computerphile
9:16
Computerphile
Рет қаралды 2,3 МЛН
Understanding Fork Bombs in 5 Minutes or Less
5:55
Engineer Man
Рет қаралды 149 М.
Why Computers Screw up Floating Point Math
12:10
Mental Outlaw
Рет қаралды 336 М.
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 6 МЛН
Теперь это его телефон
0:21
Хорошие Новости
Рет қаралды 1,7 МЛН
Обзор игрового компьютера Макса 2в1
23:34