When I was your age (old man here!), we didn't even have a floating point unit. We had to emulate it (super slow) or buy a math co-processor. But since customers never had those, we just did integer math and then did a binary shift right to divide by 64 before drawing on the screen buffer in pixels. Quake was the first major game or product that depended on having a math unit built-in.
As far my guess goes such emulations are still very useful in creating processors or robotics or even gaming consoles where programming languages don't work.. however now overall it's a diversified sector with very few people capable of understanding the concepts, and if they didn't get aware about this fact, they will be fooled and pressurised resulting in failure to earn huge money, so be super over confident if you had solved complex programming, only rarest of rare can achieve that, and all this rumours of there are lots of programmers in competition, ai will replace programmers, only non programmers can believe these lies.
@@takethat6927ha ha yeah India have programmers and nothing is outsourced from West, and reason there is rarely any website mentioning programmer details or link on their website.. haha children here can only play law sports or laziest cricket and want to claim education..
This is a solved problem for javascript programs...just use BigDecimal or a similar package. Never actually divide or multiply things if you can help it. We ran into this problem in production where the backend would store values as a decimal, but we wanted to display them to the user as a percentage. Even just the trivial * / 100 will introduce rounding errors. I would strenuously implore you to use a math package that handles this for you.
Hi Kyle i'm gonna try out nerd you 😅,15:03 the largest number that can be represented in 32 bits is not 2 to the power of 32 ( because it needs 33 bits),. The largest number is 2 to the power of 32 minus 1.
One trick I learned to count in binary, is you can use your fingers, think of each finger as a power of 2. So your first finger is 1, your second finger is 2, your first and second finger is 3, etc. Essentially you can count up to 31 on one hand and 1023 with two hands
Good explanation. I was refreshing the same thing yesterday as a very old interview question came to my head suddenly “ why do you use decimal for money?” I could not give an in-depth answer, if I can tell the precision issue in binary floating-point to interviewer , I might get that job many years ago😂
Good one, stuff like this is important. You could maybe add, that the larger the numbers you represent, the less precision you have. A good analogy is an elastic ruler: when you stretch it, the gaps between the marks get longer. So, for small numbers, it's more precise, but measuring a big number would create larger gaps between the marks, causing you to lose precision.
I'd argue that the base representation problem is not the right way to frame why software math is a problem. In languages like Racket adding 0.1 + 0.2 is fine. All number specs make a compromise between speed, accuracy, and space efficiency and floating point numbers will come with wonky behaviors like non-commutative addition. JS just happens to choose the IEEE 754 floating point as their default number type. As do many languages, but again, not all. There's no clean way to protect yourself from floating point wonkiness except to actually analyze the math you do in your software. Even OpenAI can become surprised by floating point behavior.
This is just the problem with floating point number. Other data structures like "Decimal" (in some languages) don't have this issue. The reason why floating point as the default is only because it is supported by the cpu directly and culture.
Not exactly: repeating decimal numbers exist in decimal notation as well. The result of 1/3 cannot be fully represented in decimal just as 1/10 cannot be fully represented in binary. The cultural problem is actually that languages cater for our habit of using a base 10 notation instead of their native base 2 representation: if instead of adding tenths in that example we were adding sixteenth, we wouldn't have a rounding problem :-)
I remember learning about this in college. Binary is interesting. It's also good for web devs to think about this low level stuff at least sometimes. It's not just for C++ devs only ;D
@WebDevSimplified Ah..., my university's second trimester kicked in. 🤭 Hey Kyle, make a video about React Compiler. I'm really looking forward to your in-depth video.
well that's on point, just yesterday I added a line to my JavaScript to multiply sth with (140/173) .... mayyybe I should check if the calculation isn't too far off
Only those which solved by someone else already. If you give a unique problem like nextjs 14 or a super brand new tech it will struggle and sometime cant solve at all.
When I was your age (old man here!), we didn't even have a floating point unit. We had to emulate it (super slow) or buy a math co-processor. But since customers never had those, we just did integer math and then did a binary shift right to divide by 64 before drawing on the screen buffer in pixels. Quake was the first major game or product that depended on having a math unit built-in.
As far my guess goes such emulations are still very useful in creating processors or robotics or even gaming consoles where programming languages don't work.. however now overall it's a diversified sector with very few people capable of understanding the concepts, and if they didn't get aware about this fact, they will be fooled and pressurised resulting in failure to earn huge money, so be super over confident if you had solved complex programming, only rarest of rare can achieve that, and all this rumours of there are lots of programmers in competition, ai will replace programmers, only non programmers can believe these lies.
😱🤯
👌.. yay I won ! See I commented and reported other user, proves I am the programmer of youtube...
@@takethat6927ha ha yeah India have programmers and nothing is outsourced from West, and reason there is rarely any website mentioning programmer details or link on their website.. haha children here can only play law sports or laziest cricket and want to claim education..
The actual calculation from binary (110) to decimal (6) representation is (2^2)*1 + (2^1)*1 + (2^0)*0 = 4 + 2 + 0 = 6. Otherwise, great video 👍.
This is a solved problem for javascript programs...just use BigDecimal or a similar package. Never actually divide or multiply things if you can help it. We ran into this problem in production where the backend would store values as a decimal, but we wanted to display them to the user as a percentage. Even just the trivial * / 100 will introduce rounding errors. I would strenuously implore you to use a math package that handles this for you.
To be honest, I didn't understand much, but it was exciting. Yes, keep recording such video on deep dive topics. Thanks man!
I've read about this once, but seeing that visual representation on the calculator was really good. Thanks for sharing.
Excellent explanation of a complex topic !!
Hi Kyle i'm gonna try out nerd you 😅,15:03 the largest number that can be represented in 32 bits is not 2 to the power of 32 ( because it needs 33 bits),. The largest number is 2 to the power of 32 minus 1.
Very helpful. Interesting to see how these problems were solved, to enable encoding into a binary format.
One trick I learned to count in binary, is you can use your fingers, think of each finger as a power of 2. So your first finger is 1, your second finger is 2, your first and second finger is 3, etc. Essentially you can count up to 31 on one hand and 1023 with two hands
Good explanation. I was refreshing the same thing yesterday as a very old interview question came to my head suddenly “ why do you use decimal for money?” I could not give an in-depth answer, if I can tell the precision issue in binary floating-point to interviewer , I might get that job many years ago😂
Good one, stuff like this is important.
You could maybe add, that the larger the numbers you represent, the less precision you have. A good analogy is an elastic ruler: when you stretch it, the gaps between the marks get longer. So, for small numbers, it's more precise, but measuring a big number would create larger gaps between the marks, causing you to lose precision.
I'd argue that the base representation problem is not the right way to frame why software math is a problem. In languages like Racket adding 0.1 + 0.2 is fine. All number specs make a compromise between speed, accuracy, and space efficiency and floating point numbers will come with wonky behaviors like non-commutative addition. JS just happens to choose the IEEE 754 floating point as their default number type. As do many languages, but again, not all.
There's no clean way to protect yourself from floating point wonkiness except to actually analyze the math you do in your software. Even OpenAI can become surprised by floating point behavior.
Great video and perfect length
Would love to see more videos like this where you explain how computer works.
I love and love your free courses for Next js and prisma
This was awesome! Would love more like this! 😊✨
2 the power of 0, or generally n to the power of 0 always gives 1.
Yes, what a mistake!
Yes, what a mistake!
This is just the problem with floating point number. Other data structures like "Decimal" (in some languages) don't have this issue. The reason why floating point as the default is only because it is supported by the cpu directly and culture.
Not exactly: repeating decimal numbers exist in decimal notation as well. The result of 1/3 cannot be fully represented in decimal just as 1/10 cannot be fully represented in binary. The cultural problem is actually that languages cater for our habit of using a base 10 notation instead of their native base 2 representation: if instead of adding tenths in that example we were adding sixteenth, we wouldn't have a rounding problem :-)
2 pow 0 is 1, isn't it?
Mistakes happen lol, but yeah it is 1
In the second example he says it right tho lol
literally my brain right now
It is 1. I think in the first example I was trying to say that in our particular case we have a 0 in the 2^0 place which gives us 0 since 0 * 1 is 0.
@@WebDevSimplified You got it right in the second example tho
Here's a better question: Why even have equality comparisons for floating point in an interpreted language that don't auto-correct for epsilon?
I remember learning about this in college. Binary is interesting. It's also good for web devs to think about this low level stuff at least sometimes. It's not just for C++ devs only ;D
did you calculate 2 to the power of 0, first to be 0, then to be 1?
Thanks, please do more like this!
Hi guys. Are you guys still getting tech roles? Been applying for jobs but nothing yet. Any idea on how or where to get jobs?
Great video! More like this for sure!
What keyboard you use?
@WebDevSimplified Ah..., my university's second trimester kicked in. 🤭 Hey Kyle, make a video about React Compiler. I'm really looking forward to your in-depth video.
Super interesting ! I want more videos like this :D
The first bit is either 0 or 1 - not 2^0 which would always be 1
2^0 = 1
and then 0*(2^0)=0
well that's on point, just yesterday I added a line to my JavaScript to multiply sth with (140/173) .... mayyybe I should check if the calculation isn't too far off
You could mention `Number.EPSILON`.
Thanks to computer science, I got to know such nitty-gritty ^_^
I love this so much honestly...
More like this!
awesome !
"Computers get this wrong" - no the IEEE spec gets it wrong. Many languages that don't use the IEEE don't have this rounding error.
Amazing 🎉
I wondered why this video had very less likes and realised I'm early.
2^0 = 0?
i would like more low level concepts
Legendary meme, I guess
amazing ❤
iEEE754 - we meet again
1x1 = 2 there are no straight lines
👍
Fun fact:
This is also why calculator lie to you and tell you the digits of pi are 3.141592654
(the ninth digit is wrong)
I ask for some more 👍
How to become web developer and get high pay?
Start by playing Candy Crush for 8 hrs a day.
1x1=2 lol
🙏🙏🙏🙏👏👏👏👏👏🌹🌹🌹🌹🌹🖖🖖🖖🖖🖖🖖
Computers can add 0.25+0.5 better lol
AI has significantly made coding ridiculously easy
Only those which solved by someone else already. If you give a unique problem like nextjs 14 or a super brand new tech it will struggle and sometime cant solve at all.
first!!!
Basic math💩
thanks, nice explanation but th-cam.com/video/qTXwRSksJPg/w-d-xo.html would be 7 since 2^0 equals 1.
Javascript is just like a women you cant trust those