Тёмный

Why is 0.1 + 0.2 Not 0.3 in Python? 

NeuralNine
Подписаться 349 тыс.
Просмотров 16 тыс.
50% 1

In this video we talk about why 0.1 plus 0.2 is not equal to 0.3 in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/
Timestamps:
(0:00) Intro
(1:08) IEEE-754 Explained
(9:22) Binary Representation
(15:57) How To Solve This Issue
(19:30) Outro

Наука

Опубликовано:

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 42   
@mathophile441
@mathophile441 2 года назад
I never knew something like this existed. Thanks a lot for making great in-depth Python content like these and please keep making it in the future too. Thanks:D
@ko-Daegu
@ko-Daegu 2 года назад
that's like first year Computer Sci I highly recommend reading some books that uni students go thru
@krishnanagpal807
@krishnanagpal807 2 года назад
Floats='confusing'
@ke30_
@ke30_ 2 года назад
Thank you ! Does this mean libraries such as scipy, numpy, pandas already convert numbers into Decimal instances to prevent mathematical errors ?
@complexnumbers64
@complexnumbers64 2 года назад
Nope. Numpy & friends suffer from the same floating point shenanigans as in vanilla python. For example, when working with financial (dollars & cents) data with pandas, it's something you'll commonly run into when say summing a column of transactions. You'll get a result that you'll need to round to 2 places
@Rain99891h
@Rain99891h 2 года назад
Just discovered your channel, liked and subbed :)
@benjamindreyer9884
@benjamindreyer9884 2 года назад
These videos are awesome, really awesome neovim theme:)
@bagadavid9477
@bagadavid9477 Год назад
Thank u for your class~
@ilgar.roshen
@ilgar.roshen 2 года назад
Thank You !
@somerandomuserfromootooob
@somerandomuserfromootooob 2 года назад
@NeuralNine is that 'IEE' Used in The Programming language c
@not-alot-of-options
@not-alot-of-options Год назад
7:16 for anyone getting confused at this whole "shifting 1.1 to the right" business like I was, you are shifting the *_decimal point_* of 1.1 to the right. 1.1 11 move [point] right once 110 move [point] right twice 1100 move [point] right thrice 11000 "shift 1.1 to the right four times"
@HrupekHrupencjusz
@HrupekHrupencjusz 8 месяцев назад
i am confused about it. We are shifting on binary, and then calculate binary to dig, so why you call it "decimal" shift? shift is shift. I think @neuralnine can be so nice and make good explanation for this situation?
@logothetis4771
@logothetis4771 2 года назад
It might sound stupid, but why are floats not just represented as 2 integers, one for the whole and another for the decimal part?
@NeuralNine
@NeuralNine 2 года назад
How would you represent 1.000000000008231 then?
@logothetis4771
@logothetis4771 2 года назад
ok you got me lol
@somerandomuserfromootooob
@somerandomuserfromootooob 2 года назад
@@NeuralNine i think we could do by dividing it!
@somerandomuserfromootooob
@somerandomuserfromootooob 2 года назад
@@logothetis4771 but anyway it think it is not a good idea
@somerandomuserfromootooob
@somerandomuserfromootooob 2 года назад
@@NeuralNine i mean: Take 6 We make it two int by splitting it like this 3+3 into two integers and in that way satisfies
@patrickslomian7423
@patrickslomian7423 Год назад
Thank you ;)!
@SomeCrazyVids
@SomeCrazyVids Год назад
How would it work if your exponent is much larger, lets say 101010001011 = 2699? Would you then still subtract 1023 from that? Because that leaves you with an Exponent of 2^1676? As there are only 52-bits in the Mantissa, 1676 far exceeds that, so how would you move the decimal place? Thanks
@TheJimmar12
@TheJimmar12 2 года назад
Just tried this out using the console. The same result in Javascript as well.
@mohsenhaddadi1117
@mohsenhaddadi1117 2 года назад
According to IEEE-754, is Zero equal to 2 to the power of -123 ? If so, for 64 bit system while we don't have 123 bits to shift mantissa to the left, Zero is equal to exactly Zero. but for 128 bit system Zero won't be equal to exact Zero
@ghost-ud3bm
@ghost-ud3bm 2 года назад
It's 1023 not 123. So, you'd need a 1kbit number to make a difference.
@mohsenhaddadi1117
@mohsenhaddadi1117 2 года назад
you are one of the bests
@justacoder_
@justacoder_ Год назад
Probably best thumbnail in the Universe😂🤣
@marco.nascimento
@marco.nascimento 2 года назад
Quite interesting. This is a source of various bugs if you're a beginner at programming and has no idea about the problem heh
@aditya_asundi
@aditya_asundi 2 года назад
What country are you from?
@NeuralNine
@NeuralNine 2 года назад
Austria
@jasimchouhan4784
@jasimchouhan4784 2 года назад
@@NeuralNine I thought, Du bist Deutsch.
@NeuralNine
@NeuralNine 2 года назад
@@jasimchouhan4784 ich spreche Deutsch, bin aber Österreicher
@atomicsoham4864
@atomicsoham4864 2 года назад
Let's just pretend its an easter egg in python 😉.
@jhawar-ji
@jhawar-ji 2 года назад
The motivation behind this video is one of the 64 bit floating point Kata from Code Wars.
@NeuralNine
@NeuralNine 2 года назад
Not really
@jhawar-ji
@jhawar-ji 2 года назад
@@NeuralNine ohh okay, while watching this video I thought of that Kata only😅
@ko-Daegu
@ko-Daegu 2 года назад
that's something with a lot of history (read about the f-22 Raptor or Patriot failure on desert war) floating point representation is a big topic in Computer Science
@jhawar-ji
@jhawar-ji 2 года назад
@@ko-Daegu Yeah I realised that after I started diving in scientific computing.
@SparePlayss
@SparePlayss 2 года назад
floats == weird
@emperorj4783
@emperorj4783 2 года назад
Well it makes sense for the kids that bring 0 in math
@thomasgoodwin2648
@thomasgoodwin2648 2 года назад
I still believe binary scales much better than decimal. Logs need to be brought in before any effective scaling can be achieved in decimal where binary comes with it built in. Add a bit and you have doubled the solution space. It grows geometrically rather than linearly (x10).
@kenichimori8533
@kenichimori8533 2 года назад
Download
Далее
Data Classes in Python Are The New Standard
20:34
Просмотров 66 тыс.
OVOZ
01:00
Просмотров 812 тыс.
3M❤️ #thankyou #shorts
00:16
Просмотров 4,1 млн
HUMAN BASKETBALL! 👀🏀🤣 | Triple Charm #Shorts
00:15
The last one surprised me! 👀 🎈
00:30
Просмотров 3,2 млн
5 Good Python Habits
17:35
Просмотров 400 тыс.
Python Sockets Simply Explained
39:33
Просмотров 155 тыс.
10 Nooby Mistakes Devs Often Make In Python
24:31
Просмотров 46 тыс.
Floating Point Numbers - Computerphile
9:16
Просмотров 2,3 млн
computers suck at division (a painful discovery)
5:09
Why Is This Happening?! Floating Point Approximation
5:46
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Просмотров 851 тыс.
What is The Walrus Operator in Python?
12:45
Просмотров 14 тыс.
0.1 + 0.2 is NOT 0.3 in Most Programming Languages
5:37
Main filter..
0:15
Просмотров 12 млн