Why do computers suck at math?

Ғылым және технология

What is a floating point number? And why does it produce rounding errors for programmers?
#shorts #compsci #math
Learn something? Keep the content flowing github.com/sponsors/codediodeio
Resources:
engineering. 2018/11/08...
0.30000000000000004.com/
floating-point-gui.de/formats...

Пікірлер: 3 400

  • @Fireship
    @Fireship2 жыл бұрын

    ⚡ If you wanna learn to code faster make sure to hit subscribe!!!

  • @Retrodogo

    @Retrodogo

    2 жыл бұрын

    Ok and first

  • @emilygreen72787

    @emilygreen72787

    2 жыл бұрын

    Can I say something… ok so my first video I might have broken Alexa I asked her a math question and she said 1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000ooooooooooooooooooooooo and it’s still with this subject because she couldn’t say the whole answer so it has limited ai like he’s saying.

  • @emilygreen72787

    @emilygreen72787

    2 жыл бұрын

    And I will sub

  • @Shad0wBoxxer

    @Shad0wBoxxer

    2 жыл бұрын

    Is this with calculators as well

  • @user-xu1zd6qc2t

    @user-xu1zd6qc2t

    2 жыл бұрын

    @@emilygreen72787 KZread Calculator released.

  • @coompiler9029
    @coompiler90293 жыл бұрын

    if (num1 == 0.1 && num2 ==0.2) { return 0.3 } There we go solved it

  • @Fireship

    @Fireship

    3 жыл бұрын

    That's clean!

  • @NeRoNzXz

    @NeRoNzXz

    3 жыл бұрын

    and what if num1 is 0.2 and num2 is 0.1?

  • @csangale

    @csangale

    3 жыл бұрын

    AI can solve it 👍 try and tell

  • @yt-sh

    @yt-sh

    3 жыл бұрын

    @@NeRoNzXz if (num1 == 0.1 && num2 ==0.2) { return 0.3 } else if (num1 == 0.2 && num2 ==0.1) { return 0.3 }

  • @miniappletheapple

    @miniappletheapple

    3 жыл бұрын

    @@yt-sh no if(num1 == 0.1 && num2 == 0.2 || num1 == 0.2 && num2 ==0.1){ return 0.3 }

  • @tanmay______
    @tanmay______3 жыл бұрын

    Finally, I can now show this to mom and tell her I’m better than computers

  • @yt-sh

    @yt-sh

    3 жыл бұрын

    no you're not (burp) Morty

  • @Flame_Dev

    @Flame_Dev

    3 жыл бұрын

    Ohhh look whole cartoons are coming together here XD

  • @newaz1268

    @newaz1268

    3 жыл бұрын

    definitely worth it!

  • @Nicolas_Payne

    @Nicolas_Payne

    2 жыл бұрын

    Also, this is the reason the far lands occurs/occurred in Minecraft. The farther and farther out you go, the less and less accurate player movement becomes.

  • @filthyweebs759

    @filthyweebs759

    2 жыл бұрын

    You tell mom and she says no more computer for you

  • @AIM-9X_Sidewinder
    @AIM-9X_Sidewinder Жыл бұрын

    "your computer sucks at math" calculator: my objectives are beyond your understandings

  • @SAIHTAM20Y

    @SAIHTAM20Y

    11 ай бұрын

    Yeah even my phone calculator is smarter so i dont understand the problem

  • @flyinhigh7681

    @flyinhigh7681

    11 ай бұрын

    ​@@SAIHTAM20Yany computer can be made to do exact decimal math, thats not what programming languages are doing though, because doing exact decimal math is slow and sucks, doing limited precision binary math is fast and cool, so your computer does that instead. Where precision matters (or where speed doesnt) you can do exact math, hence why a calculator gives the exact answer. Where speed does matter (such as in a computer processor) you go for the faster but slightly more imprecise math, and it is good enough

  • @qwaeszrdxtfcgvbqwaeszrdxtf5733

    @qwaeszrdxtfcgvbqwaeszrdxtf5733

    11 ай бұрын

    Dude all computers are a calculator

  • @EthanMckinnell

    @EthanMckinnell

    7 ай бұрын

    @@SAIHTAM20Y the calculator app rounds it, but when it comes to raw computing then yes they are dumb, your phone is still technically dumb however it is hidden

  • @jesterram7146

    @jesterram7146

    4 ай бұрын

    ​@@EthanMckinnellnah the calc app isn't rounding the incorrect answer it just using a different version of addition. cause it ONLY has to calculate it uses a precise but slow method. since Java and python do way more they're a bit sloppy to go faster

  • @AmanSingh-wk4qu
    @AmanSingh-wk4qu2 жыл бұрын

    To be exact, it's a limitation of the IEE754 floating point standard. There are implementation of arbitrary precision floating point libraries (aka bignums) but they're slower and less optimised for modern CPUs

  • @QuintinMassey

    @QuintinMassey

    9 ай бұрын

    I made a similar comment. The person who made the video should attempt to be more precise rather than saying “the computer sucks at math.” It only does what you tell it, so actually you suck at math 😢

  • @davidgillies620

    @davidgillies620

    5 ай бұрын

    They still can't exactly represent numbers whose denominator is not a power of 2 (dyadic rationals). And by judicious use of SIMD instructions multiprecision libraries such as MPFR can be made much more efficient for calculations close to machine precision.

  • @__christopher__

    @__christopher__

    4 ай бұрын

    @@davidgillies620 Computers "suck" at math the same way humans "suck" at math when they claim that 1/3=0.33 or pi=3.14. And yes, you can write rational number types that are exact (as long as neither the numerator nor the denominator overflows).

  • @TheApeiros

    @TheApeiros

    3 ай бұрын

    Fun fact: IEEE754 also specifies a decimal variant. Just that basically no hardware supports that.

  • @leovillant768

    @leovillant768

    Ай бұрын

    nigum

  • @morethanjustasloth5528
    @morethanjustasloth55282 жыл бұрын

    “JavaScript is a toy language, so I tried Python instead.” Hahahahaha

  • @NZIsaacNZ

    @NZIsaacNZ

    2 жыл бұрын

    As compared to what?

  • @LordSwordbreak

    @LordSwordbreak

    2 жыл бұрын

    @@NZIsaacNZ You will C.

  • @morethanjustasloth5528

    @morethanjustasloth5528

    2 жыл бұрын

    @@NZIsaacNZ Compiled Languages.

  • @zezogamer8567

    @zezogamer8567

    2 жыл бұрын

    Imagine not using java, c++, c, rust, or go CRINGE

  • @NZIsaacNZ

    @NZIsaacNZ

    2 жыл бұрын

    @@LordSwordbreak as compared to segmentation fault?

  • @Pixelcraftian
    @Pixelcraftian2 жыл бұрын

    _”Good job on solving all of the tough questions, this one is the money shot, what’s 0.1 + 0.2?”_ The computer: 😓

  • @untitledtruth921

    @untitledtruth921

    2 жыл бұрын

    i like 0001 0011 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0100

  • @UnSolved_Myst

    @UnSolved_Myst

    2 жыл бұрын

    Didn’t expect to see you here

  • @professionalmexican7919

    @professionalmexican7919

    2 жыл бұрын

    @@UnSolved_Myst let the man comment!

  • @celineragnarto6546

    @celineragnarto6546

    2 жыл бұрын

    How is 0.1+0.2 wrong? What’s the formula supposed to be? I’m still in junior high I wanna learn something.

  • @uniques.5443

    @uniques.5443

    2 жыл бұрын

    if you do ( (0.1 x 10) + ( 0.2 x 10) ) / 10 will give you 0.3

  • @marc-io
    @marc-io2 жыл бұрын

    It's funny that he assumed JS was broken and thought python wouldn't

  • @amberwingthefairycat

    @amberwingthefairycat

    Жыл бұрын

    I’m pretty sure he was already aware of this rounding issue and he just wanted to have some fun

  • @JacobSantosDev

    @JacobSantosDev

    Жыл бұрын

    The difference is that there are precision options in Python... And JavaScript and other languages

  • @oscardbg9654

    @oscardbg9654

    Жыл бұрын

    what about JS sorting method... it outputs [1,11,111,2,3,4] i.e.

  • @JacobSantosDev

    @JacobSantosDev

    Жыл бұрын

    @@oscardbg9654 I think that problem is between keyboard and chair

  • @oscardbg9654

    @oscardbg9654

    Жыл бұрын

    @@JacobSantosDev lmao, it seems you haven't seen that before, I hope you can declare an array and use the sort method... Try it and you'll see that "bug" idk but works in a weird way

  • @joaovgarcia
    @joaovgarcia2 жыл бұрын

    damn i wish there was a longer version explaining more on this topic

  • @eduardogarcia6318

    @eduardogarcia6318

    Жыл бұрын

    If you're interested on it, you could search on how floating point numbers work. Here's a short and simple explanation, tho Let's say you have 64 spaces to be able to save any number from 30,000 to -30,000 and with all its decimals. It's an insane range for such a little space. So the way to work this out is, exponential numbers. You'll have the 64 spaces divided like this: First one is sign (so you know if it's positive or negative) Next 11 are the exponential And last 52 are the base, or mantissa You can use this to have a very wide range of numbers, because of the exponent, but you only have a precision of 52 bits, so you'll lose information. It's like if we said 3x10⁹ We're able to represent a large number (3 billions) in only 5 spaces, but we can't know if it's 3 billions and 1, because we only have those 5 spaces and we have to get as close as we can.

  • @PipocaQuemada

    @PipocaQuemada

    Жыл бұрын

    You probably remember scientific notation from school, where you write numbers as a*10^b. For example, 5.324 * 10^21. It's easy to build hardware that can add, multiply, etc. numbers of the form a*2^b, given fixed ranges for a and b. This is very fast and efficient, but there are no integer solutions for a and b in the equation 1/10 = a/(2^b).

  • @lukes3845

    @lukes3845

    Жыл бұрын

    Jan Misali has a good video on this. You should be able to find the video by searching his name and “floating point”

  • @Murzac

    @Murzac

    Жыл бұрын

    In all simplicity this is the same thing as trying to write down 1/3 as a decimal. You'll go 0.333333333... but you can never write the full number down because the number of 3's is infinite. 0.1+0.2 in binary just results in the same exact kind of infinite number in binary, so when you convert it to base 10, you see the artifact of this rounding error as the random 4 at the end.

  • @SketchyJohnny

    @SketchyJohnny

    Жыл бұрын

    Tom Scott has a great video about floating point numbers

  • @FingerprintGamer
    @FingerprintGamer2 жыл бұрын

    I remember debugging my code for a week until i realised it was the freakin rounding system

  • @yuridavila6095

    @yuridavila6095

    2 жыл бұрын

    Bruh wat this was first semester knowledge of my computer science class

  • @rokisok9618

    @rokisok9618

    2 жыл бұрын

    @@yuridavila6095 yeah but just because you know about the concept doesn’t mean your mind will immediately jump to that particular concept as the reason for the bug immediately.

  • @EragonShadeslayer

    @EragonShadeslayer

    2 жыл бұрын

    @@yuridavila6095 Ok but some people like me just learn programming at home.

  • @dierandomdie

    @dierandomdie

    2 жыл бұрын

    @@yuridavila6095 I've been in "first semester" comp sci for two different languages and neither ever spoke of this.

  • @yuridavila6095

    @yuridavila6095

    2 жыл бұрын

    @@dierandomdie Might depend on the quality of your university, what do you even mean by first semester of two languages? Comp sci is a single degree or do you mean you went to two different boot camps?

  • @roua.
    @roua.3 жыл бұрын

    today I (finally) learned the meaning of "floating" in floating point. great vid

  • @okachobe1

    @okachobe1

    3 жыл бұрын

    Same

  • @jackkirby5287

    @jackkirby5287

    3 жыл бұрын

    Same

  • @marflage

    @marflage

    3 жыл бұрын

    Same

  • @JeekyllFrost777

    @JeekyllFrost777

    3 жыл бұрын

    Same

  • @shivamprakash6796

    @shivamprakash6796

    3 жыл бұрын

    Same

  • @flamesnail
    @flamesnail Жыл бұрын

    I know in python it’s fixed with: from decimal import Decimal X=Decimal(‘0.1’) Y=Decimal(‘0.2’) print(X+Y)

  • @UwOtt

    @UwOtt

    6 ай бұрын

    Ew

  • @Zubuu

    @Zubuu

    2 ай бұрын

    Disgustingggg

  • @82NeXus
    @82NeXus Жыл бұрын

    For anyone wondering, the solution, if you want exact decimal arithmetic, is to use a decimal library, such as Python's decimal module.

  • @webnplay

    @webnplay

    Жыл бұрын

    or just use a proper language xD

  • @neomarrodriguez9255

    @neomarrodriguez9255

    Жыл бұрын

    ​@@webnplaythis isn't a language problem, this is how computer are intended to work. It's a trade off, you sacrifice precision for efficient math

  • @wanderingbufoon
    @wanderingbufoon2 жыл бұрын

    "Computers use base 2 while humans use base 10" Me: "the future is not now, young kid"

  • @proxyhx2075

    @proxyhx2075

    2 жыл бұрын

    I think I understand big guy

  • @NightFyreTV

    @NightFyreTV

    2 жыл бұрын

    Computers actually use base 16 , well. Programs do anyways

  • @saltytoxicity2172

    @saltytoxicity2172

    2 жыл бұрын

    @@NightFyreTV Ehhhm, no Computers are base 2 because they only have 2 states: on and off (current flowing and no current flowing). Machine Code gets printed as hexadecimal (base 16) for readability. Under the hood though, its all ones and zeroes.

  • @user-fk8hc6rq3v

    @user-fk8hc6rq3v

    2 жыл бұрын

    Interestingly, although base-10 is a very common base in human languages, not all languages use it, so 'humans' in general don't just use base-10

  • @user-tr8kr1jd2o

    @user-tr8kr1jd2o

    2 жыл бұрын

    @@NightFyreTV they don’t. The state of each bit is still either HIGH or LOW in a modern computer, hexadecimal is just a more convenient way to compress the human readable form of a number while preserving the location (since its very very easy for a human to convert between base 2 and 16 in their head)

  • @animeblackguy_1694
    @animeblackguy_16942 жыл бұрын

    “javascript is just a toy language tho” *church bells toll*

  • @beatalert123

    @beatalert123

    2 жыл бұрын

    😁😁

  • @johnnyplays2843

    @johnnyplays2843

    2 жыл бұрын

    So is python lmao

  • @monodragon

    @monodragon

    2 жыл бұрын

    older versions of minecraft:

  • @Qbe_Root

    @Qbe_Root

    2 жыл бұрын

    @@monodragon That's Java, a completely different language

  • @TruthAndLoyalty

    @TruthAndLoyalty

    2 жыл бұрын

    Theres way too much in production using javascript to call it a toy language.

  • @hudmo4193
    @hudmo4193 Жыл бұрын

    Just came through Modeling Methods at university, where we discuss all the ways to circumvent this and other computer problems when performing math ops. Pretty interesting

  • @Jazzerizer
    @Jazzerizer Жыл бұрын

    that animation is perfect

  • @bgaabt
    @bgaabt3 жыл бұрын

    "And that's why your computer sucks at math" - the stupid machine can't even calculate an 18-digit number correctly

  • @softwarelivre2389

    @softwarelivre2389

    3 жыл бұрын

    Until you use bigfloat hehehe

  • @Kyle-xk2rb

    @Kyle-xk2rb

    3 жыл бұрын

    hAvE yOu hEaRd oF BigInt?

  • @SameerSk

    @SameerSk

    3 жыл бұрын

    @@Kyle-xk2rb BigInteger java fam

  • @ignore2466

    @ignore2466

    2 жыл бұрын

    @@SameerSk looOOooong

  • @tanker242

    @tanker242

    2 жыл бұрын

    That's just the limit of the data type you're using.

  • @marcframe7449
    @marcframe74493 жыл бұрын

    create two accounts in your bank. #1 with all your money #2 with 0.1 cents move 0.2 cents from #1 to #2 then move 0.20000000000000004 back to #1 rinse and repeat

  • @smotbutterman1127

    @smotbutterman1127

    3 жыл бұрын

    Get charged a flat rate of 3 for every movement. Get boned.

  • @umnikos

    @umnikos

    3 жыл бұрын

    That's why all (sanely designed) banking systems use integers to represent amounts.

  • @Mia-cw1du

    @Mia-cw1du

    3 жыл бұрын

    @@umnikos czech banks: hold my beer

  • @leoingson

    @leoingson

    3 жыл бұрын

    It's been done with stacking up rounding errors of interest rates - guy got caught, tho.

  • @TomasNavickas

    @TomasNavickas

    3 жыл бұрын

    ​@@umnikos lol what integers? Max size would be 2 billions. They use bigdecimals

  • @Sal1981
    @Sal1981 Жыл бұрын

    That's why in Python you use the Decimal type, which stores rounding errors when doing calculations, eliminating them. Pretty important when you do finance calculations or any other calculation that requires +15 digit precision.

  • @vii-ka
    @vii-ka Жыл бұрын

    in floating point math, any number is not a number and actually means the range of numbers too small to be distinguished from this number

  • @enra8557
    @enra85573 жыл бұрын

    Oh man thanks. I can sleep now

  • @enra8557

    @enra8557

    3 жыл бұрын

    @Hand Grabbing Fruits don't call that bug. It's feature

  • @kaspermaaa
    @kaspermaaa3 жыл бұрын

    "javascript is just a toy-language" *tries python*

  • @brotherindeed992

    @brotherindeed992

    3 жыл бұрын

    I use c and i think this hasn't happend to me ever but too lazy to try C++ gand forever.

  • @strawberrysausageinc375

    @strawberrysausageinc375

    2 жыл бұрын

    Python... Does it even Count AS a real language ?... Its as easy as Scratch... Okay... Nevermind... They told us in Computer Science Lesson, that scratch is a Programming language... So yeah... I guess Python counts

  • @cherryramatis2508

    @cherryramatis2508

    2 жыл бұрын

    @@strawberrysausageinc375 well, google use python for basically 60% of it's system, so I think it counts

  • @strawberrysausageinc375

    @strawberrysausageinc375

    2 жыл бұрын

    @@cherryramatis2508 Just curious... But where do you get that Numbers from... How do you know ?

  • @strawberrysausageinc375

    @strawberrysausageinc375

    2 жыл бұрын

    @@mesoseven1633 I guess its weird to Use if you are Not used to using library's for basically everything... It doesn't realy matter what you want to do... You have to understand how the Library you need for the Project works... and Not all of the Library's have good Documentation

  • @Jepleg
    @Jepleg11 ай бұрын

    Omg I thought that the little stick man at the bottom looked like one of those senseis but it was actually his arms 😅😂

  • @Saxophonin
    @Saxophonin11 ай бұрын

    For python you can use the decimal module.

  • @hackedxd2813
    @hackedxd28132 жыл бұрын

    JavaScript is just a toy language, so I tried it in Python. Lmao 🤣🤣

  • @Une6sy

    @Une6sy

    Жыл бұрын

    Reject Java embrace C#

  • @aubrey-levreau

    @aubrey-levreau

    Жыл бұрын

    It's true tho JS kinda a joke

  • @hjrgf

    @hjrgf

    Жыл бұрын

    ​@@Une6sy i used to code in c# it was enjoyable i switched to c++ took me 4 hours just to install the compiler acidentally used gcc instead of g++ forgot a " so i got errors forgot a ; so even more errors and all of this for hello world

  • @Une6sy

    @Une6sy

    Жыл бұрын

    @@hjrgf lmao I’m not very good but stackoverflow has been a good tool and now chat gpt

  • @webnplay

    @webnplay

    Жыл бұрын

    @@Une6sy Reject C# embrace C++

  • @michaelpoggers2407
    @michaelpoggers24073 жыл бұрын

    To be more specific, its like when you add 1/3 + 1/3 + 1/3 and get 0.99999999 as 1/3 is a recurring number, you store it as 0.33333333 in base 10. Same with base 2, both 1/10 and 2/10 (0.1 and 0.2) are recurring. And when you add 0.5 and 0.25 you'll get a correct result because both are not reccuring in base 2.

  • @nachnamevorname9801

    @nachnamevorname9801

    3 жыл бұрын

    Thanks!

  • @marflage

    @marflage

    3 жыл бұрын

    This makes total sense. Thanks

  • @nonconsensualopinion

    @nonconsensualopinion

    3 жыл бұрын

    And to elaborate on your excellent comment, you'll get an infinite recurring number if the prime factors of your denominator are not a subset of the prime factors of your base, or radix. In base 10, the prime factors of 10 are 2 and 5. So we can write 1/2 easily as 0.5 because 2 is in our set of prime factors of our base. 1/5 is 0.2. no problem. 1/4 is 0.25. easy because 4's prime factorization is 2x2. 1/3 is 0.33333333333 forever because 3 is its own prime factor and not 2 or 5. So in computers our radix is 2. So we can only precisely represent fractions with a denominator is powers of 2, eg 1,2,4,8, etc.

  • @awkwardnerd.

    @awkwardnerd.

    2 жыл бұрын

    Nah I tried it it gives you 1 as an answer

  • @beatalert123

    @beatalert123

    2 жыл бұрын

    Meanwhile: le humans: who let the nerds out, who, who who who 😆

  • @overcritical304
    @overcritical304 Жыл бұрын

    That is why CPUs have an option called "Rounding Control". Or RC register.

  • @Cathay3520
    @Cathay3520 Жыл бұрын

    teacher "you only scored 40% in the test" me "lemme show you something"

  • @Justcause641
    @Justcause6413 жыл бұрын

    0.1 is a recurring decimal in binary the same way 1/3 is recurring in base 10. Base 2: 0.1 + 0.2 != 0.3 Base 10: 0.33 + 0.33 + 0.33 != 1.0

  • @slaitm9289

    @slaitm9289

    2 жыл бұрын

    But 0.3 recurring times 3 IS 1.0. And 0.1 + 0.2 is equal to 0.3 no matter the base.

  • @Henriki2305

    @Henriki2305

    2 жыл бұрын

    @@slaitm9289 when calculating with computers there is no infinitely recurring decimals, 0.3 x3 = 0.9, 0.33x3 = 0.99, 0.333x3=0.999, no matter how big amount of data pc can store, the answer pc will get is always slightly less than 1. Same goes for 0.1 since it is recurring in base 2, pc can never store it in a way that is exactly 0.1, the last bit(s) will always be a bit inaccurate and you get a bit over the correct answer

  • @slaitm9289

    @slaitm9289

    2 жыл бұрын

    @@Henriki2305 Should have clarified that you are talking about the implementation in computers. Right now it seems like the errors mentioned in the video are actually correct and just a characteristic of the different base

  • @kjn5991
    @kjn59913 жыл бұрын

    "Javascript is just a toy language".... congratz, you just triggered over half of developers following this channel :D

  • @joaomendoncayt

    @joaomendoncayt

    3 жыл бұрын

    There's 2 types of JS devs here. The ones who will laugh at his joke and the ones crying because he "offended" his favorite tech ahahah awesome.. this guy is a genious

  • @cenacr007

    @cenacr007

    3 жыл бұрын

    aye

  • @huaweiespionandotudo8637

    @huaweiespionandotudo8637

    2 жыл бұрын

    But it's

  • @wasabithumbs6294

    @wasabithumbs6294

    2 жыл бұрын

    I mean, there's a reason people usually move onto JavaScript (maybe python) after Scratch, rather than C languages for instance

  • @juliaf_

    @juliaf_

    2 жыл бұрын

    @@wasabithumbs6294 there's also a reason why python is so widely used. It's easy to write and easy to understand. As long as you don't care about speed, it's nearly a perfect language. I'd recommend starting with c++ or c# before Python though cause it's easier to learn other languages if you know a c language than python

  • @ShinyRowletGuy
    @ShinyRowletGuy Жыл бұрын

    "I like your funny words magic man"

  • @nathanberrigan9839
    @nathanberrigan9839 Жыл бұрын

    This is why a lot of financial systems don't use floating point, but instead store money as an integer number of pennies (or milles) and then throw in the decimal on the display.

  • @fatgolem69
    @fatgolem693 жыл бұрын

    now i know that my computer sucks at math Thanks Fireship

  • @smotbutterman1127
    @smotbutterman11273 жыл бұрын

    My computer also sucks at choosing things randomly. Can you make a video about that too, bro?

  • @chrismesogitis9310

    @chrismesogitis9310

    3 жыл бұрын

    It can't produce any unpredictable number because in its core the commands and the circuit is specific so nothing unpredictable can come out of it.That's why it produces pseudo-random values who are predefined by a complex function to seem random.

  • @priyanshusharma6763

    @priyanshusharma6763

    3 жыл бұрын

    This is normal bro :`)

  • @jackkirby5287

    @jackkirby5287

    3 жыл бұрын

    True. Pseudo randomness is randomly not random

  • @sankalp2520

    @sankalp2520

    3 жыл бұрын

    just add an analog device to read white noise, like an oscilloscope when its probes are left in air, it shows random signal.

  • @sankalp2520

    @sankalp2520

    3 жыл бұрын

    but i think pseudo-random numbers are more useful than random numbers. U can create the exact set of pseudo-random numbers if you know the seed value.

  • @delavegamarvin2443
    @delavegamarvin2443 Жыл бұрын

    A workaround I've learned is to store the whole number and fraction to string. When you calculate the numbers, convert the strings to Decimal(C#) and apply calculation. This way you can have a very high precision number implementation.

  • @TheWhiteMamba3000
    @TheWhiteMamba3000 Жыл бұрын

    I have always wondered why when using the functions in Excel, there will be extra numbers as a rounding error. However, if you manually enter the equation instead of a function, it tends to be more exact.

  • @wasabithumbs6294
    @wasabithumbs62942 жыл бұрын

    This is incomplete. Less abstracted programming languages will support "double" and sometimes "BigDecimal" datatypes among others rather than floats. Depending on how stupid you want to get, calculations within a reasonable range will be 100% accurate. This would be suitable for applications like banking or cryptography. Not that it matters anyway, I remember hearing that 9 digits of pi is all that is required to calculate the radius of the observable universe within the size of a hydrogen atom?

  • @wasabithumbs6294

    @wasabithumbs6294

    2 жыл бұрын

    @@codymiller5468 Oops. Thanks!

  • @terrywright9765

    @terrywright9765

    2 жыл бұрын

    As an old school Fortran programmer, I am impressed you know about 'double precision'.

  • @redberry4420

    @redberry4420

    2 жыл бұрын

    @@codymiller5468 because of how ridiculously small the numbers get though, 39 digits really isn’t much considering the enormity of the observable universe and the size of an atom

  • @moihawk666

    @moihawk666

    2 жыл бұрын

    I love this and just said pretty much the same thing ….. #realnerds

  • @moihawk666

    @moihawk666

    2 жыл бұрын

    @@terrywright9765 I’m a new school C# programmer and doubles is a basic unit of measurement, we have come so far.

  • @yourDecisi0n
    @yourDecisi0n3 жыл бұрын

    I think explaining how to solve this issue would make a great idea for a video :D

  • @bhaveshladdagiri2675

    @bhaveshladdagiri2675

    3 жыл бұрын

    Simply rounding up the decimal places should do the job. For example: a = 0.3 - 0.1 > 0.19999999999999998 a.toFixed(2) > 0.20 p.s. toFixed might return a string so you can simple do parseFloat(a.toFixed(2)) to get a number

  • @raiyansarker3809

    @raiyansarker3809

    3 жыл бұрын

    I don't think it is an issue, computers work like this. It has nothing to do with programming languages!

  • @zyansheep

    @zyansheep

    3 жыл бұрын

    @@bhaveshladdagiri2675 also rational number specifications that support fractions

  • @skynliner3434

    @skynliner3434

    3 жыл бұрын

    @@bhaveshladdagiri2675 dude parsing is slow, it shouldn't be a general solution. jsben.ch/yCfVY

  • @t_kon

    @t_kon

    3 жыл бұрын

    Simple answer, you don't. In general, if you can avoid floating point then avoid it. Only use it if it's necessary.

  • @Lampe2020
    @Lampe202011 ай бұрын

    We should create a more calculation-error-resistant number format to replace floats and doubles, like store the number before and after the decimal point, prepended with a header of 6 bits that tells the bit where the after-decimal-point digits begin. Then convert the whole thing to any other number base when needed.

  • @carcedopro7285
    @carcedopro7285 Жыл бұрын

    you actually can solve the issue in python by using decimal which is Base-10, for example: from decimal import Decimal print(Decimal("0.1") + Decimal("0.2")) # Output: 0.3 You should always use decimal for sensitive calculations

  • @EJ-jh1vf
    @EJ-jh1vf2 жыл бұрын

    POV: you are about to go look at .1+.2 in JS and Python

  • @whyareureadingthis6719
    @whyareureadingthis67192 жыл бұрын

    I'm studying python as part of my math course in uni, this is the first thing they told us since alot of out detailed codes could be ruined by these rounding errors

  • @RockSleeper
    @RockSleeper2 жыл бұрын

    unexpectedly and gratefully learned why it's called floating point, thanks.

  • @iben1195
    @iben119511 ай бұрын

    Funny thing I was increasing the opacity of an image using setTimeInterval with a 0.2 step and was surprised it never amounted to exactly 1

  • @erichahn3336
    @erichahn33362 жыл бұрын

    Base 2 is not the problem. You would have the same problems for base-10 floats. The actual problem is that the mantissa and the exponent have a limited amount of bits available to represent a float. This means that on the real axis floats are weirdly scattered and since operations on floats must return floats we will get rounding errors.

  • @athingwhichexists

    @athingwhichexists

    2 жыл бұрын

    was typing this up but decided to check if someone else was going to point it out, thanks man. All the base 2 does is make the errors bigger after converting back to base 10, but the errors were already present in base 10 to begin with thanks to trunkation

  • @MisterBerdill
    @MisterBerdill2 жыл бұрын

    Just had a lecture about this the other day! Really interesting stuff, explains a lot of weirdness from my first days of coding!

  • @hunterlepage
    @hunterlepage Жыл бұрын

    Homie you can't call the robot dumb if you're using a calculator for 0.1+0.2

  • @samygafsi6429
    @samygafsi6429 Жыл бұрын

    About a month ago I had to struggle with this and it drove nuts. Good thing I had a friend (also a developper but with experience) and he explained it to me. If any beginner encounters something similar : if it's just one or two variables just multiply everything by 10 or 100 or something. And don't forget to divide by that number at the end before displaying the result. Don't try to solve the issue in a very complex way, at least not at the first lessons. You will have plenty of time in the future to do so.

  • @shan_singh
    @shan_singh2 жыл бұрын

    "Javascript is a toy language" me wo spent hours learning it : 👁👄👁

  • @siliconhawk9293

    @siliconhawk9293

    2 жыл бұрын

    learning anything takes time tbh

  • @codewithsheikh2805

    @codewithsheikh2805

    2 жыл бұрын

    It's use to be now it's almost multi general purpose language

  • @gawizard4980

    @gawizard4980

    2 жыл бұрын

    hours?

  • @androdeveloper7261

    @androdeveloper7261

    2 жыл бұрын

    @@gawizard4980 XD :-D

  • @androdeveloper7261

    @androdeveloper7261

    2 жыл бұрын

    So have you stopped wasting your time ?

  • @Hiatuz4
    @Hiatuz42 жыл бұрын

    I love this channel. He's like a guy that randomly pops up and tell you useful info that will help you in the future.

  • @lodestar3984
    @lodestar3984 Жыл бұрын

    I feel so proud of myself for knowing this. I learned this in my Comp. Sci. 1 class.

  • @TheQuark6789
    @TheQuark678911 ай бұрын

    FYI, this is why you NEVER use floating point numbers to count money.

  • @DerpDahFlerp
    @DerpDahFlerp2 жыл бұрын

    First time I've seen a computer programming video and felt proud of my own knowledge. Small win, but I'll take it!

  • @doggo_woo

    @doggo_woo

    2 жыл бұрын

    I learnt about this watching a video explaining why in serious Sam the weapons slow down after a while. The reason was because the weapons used a timer with a float data type

  • @somebrid2147
    @somebrid21472 жыл бұрын

    If JS is a toy python needs to fall under the same category imo.

  • @Tyler-jd3ex

    @Tyler-jd3ex

    2 жыл бұрын

    no brackets = weird

  • @somebrid2147

    @somebrid2147

    2 жыл бұрын

    @@Tyler-jd3ex agreed. It even won an award for readability..

  • @Tyler-jd3ex

    @Tyler-jd3ex

    2 жыл бұрын

    @@somebrid2147 PYTHON???? the spacing is hell

  • @abhinavjha3082

    @abhinavjha3082

    2 жыл бұрын

    @@somebrid2147 Might as well fucking use English at that point

  • @NoName-oi6vw

    @NoName-oi6vw

    2 жыл бұрын

    @@abhinavjha3082 englishScript: The function dance will make the computer dance If your mom is stupid, dance **Computer starts dancing**

  • @rubansrirambabu7771
    @rubansrirambabu77712 жыл бұрын

    As part of one of our assignments, we had to compare and do arithmetic with floating point values as well, and it was very important that we accurately compare two floats. One solution most of us thought of us was to do the comparison and keep a small tolerance level to make up for IEEE 754 representation of floats. My friend decided to just implement a class that represents floats as rational values (in the form a/b, where a and b are ints). It works well, however you won't get a lot of precision, not as much as float.

  • @Carden__
    @Carden__10 ай бұрын

    I have no godamn idea about what he just said, but he got me interested to watch the whole short ;-;

  • @inactiveaccount4829
    @inactiveaccount48292 жыл бұрын

    Just watched on of your threejs vids as I’m learning about 3D rendering for fun as I usually spend my day on JavaScript algorithms. Your tutorial style is super easy to understand, and they’re fun to follow. Appreciate my guy

  • @windubitably
    @windubitably3 жыл бұрын

    The animation of the decimal moving left to right in the same sequence of numbers was the most efficient way to explain the FLOATING part of floating point.

  • @zaid6527
    @zaid652710 ай бұрын

    Same precision error is there in pow() function in c++, because it uses double arithmetic, that's why we use modular exponentiation for precise calculation.

  • @Moloch-zh8uc
    @Moloch-zh8uc5 ай бұрын

    For those interested in reading more the technical term for it is machine epsilon

  • @idontknowwhatimdoing8941
    @idontknowwhatimdoing89413 жыл бұрын

    Damn and i was gonna send my computer to take my math exam instead of me, thanks Fireship.

  • @fl3tched
    @fl3tched2 жыл бұрын

    His face when he learns to cast numbers as an int data type :O

  • @gigabowser2031

    @gigabowser2031

    2 жыл бұрын

    Then it wouldn't be a decimal. You could technically do (1+2)/(float)10 but you have to cast the 10 as a float so it preforms the division correctly.

  • @sachinkainth9508
    @sachinkainth95082 жыл бұрын

    This is why languages like C# have decimal types for doing such calculations.

  • @treeplate512
    @treeplate51211 ай бұрын

    this is a real problem when making a calculator, half of the actual calculating is correcting for floating-point errors with string manipulation

  • @kevinfuller97
    @kevinfuller972 жыл бұрын

    I remember finding out about floating point and just like being absolutely mind blown how extra but necessary it was

  • @totoplopp6630
    @totoplopp663011 ай бұрын

    This is why cobol is still used to this day

  • @Handle.Youtube.
    @Handle.Youtube.11 ай бұрын

    Bro went Vsauce mode

  • @gurbux6491
    @gurbux64913 жыл бұрын

    "JavaScript is a toy language." had me in splits 🤣

  • @Dan_ny
    @Dan_ny3 жыл бұрын

    "JavaScript is just a toy language" Triggered :)

  • @rapianopenaldo1669

    @rapianopenaldo1669

    3 жыл бұрын

    Its a joke...he knows javascript is literally one of the best languages out there :)

  • @jackkirby5287

    @jackkirby5287

    3 жыл бұрын

    @@rapianopenaldo1669 next to Java, that is ;)

  • @rapianopenaldo1669

    @rapianopenaldo1669

    3 жыл бұрын

    @@jackkirby5287 java is too verbose in my opinion...gets annoying in large projects....also i love the functional programming in javascript and how it handles asynchronous tasks with async await

  • @vishalmakhija2616

    @vishalmakhija2616

    3 жыл бұрын

    Python gave the same result

  • @kkkbuta5
    @kkkbuta52 жыл бұрын

    I already graduated with a computing degree and I just learnt why it's called floating point

  • @OctagonalSquare
    @OctagonalSquare Жыл бұрын

    What’s wild is in all my experience programming, I’ve not come across this error. I hear about it a lot, but have not witnessed it in my code

  • @edgaredge3971
    @edgaredge39712 жыл бұрын

    Just keep track of your significant figures and decimal places and it will always be correct. All good scientists and math mathematicians use sig figs when multiplying and decimal places when adding to cut out all the uncertainty in their figures. This video shows a prime example of why you should have only rounded to the first decimal place.

  • @Mrcake0103

    @Mrcake0103

    2 жыл бұрын

    ...what? Significant figures are for keeping track of the uncertainty inherent to real world measurement and guesstimates. Very little of that (if any) applies to mathematics. “Idunno dude, like, pretty close to 2” is not an acceptable answer when the actual solution is the square root of 9.

  • @Julioyowyo
    @Julioyowyo2 жыл бұрын

    Thanks! Now I know the practical answer to 3D problems I've found for decades and not knowing what!

  • @elietheprof5678
    @elietheprof56782 ай бұрын

    Hot take: Floating point comparisons should offer a margin of error by default.

  • @HXMCPP
    @HXMCPP2 жыл бұрын

    the xmm regs handle that super well tho ...

  • @poopfartlord9695
    @poopfartlord96952 жыл бұрын

    The floating point error can be really important in digital signal processing applications, and can lead to a variety of weird pretty much undebugable problems.

  • @vipvip-tf9rw

    @vipvip-tf9rw

    2 жыл бұрын

    imagine how banks solved this problem

  • @bjornnilden260
    @bjornnilden2602 жыл бұрын

    This is why you never use floating point when you need accuracy.

  • @uwufemboy5683

    @uwufemboy5683

    2 жыл бұрын

    If you need accuracy to the point that would be affected by floating point rounding errors, either you’re doing quantum mechanics or your code is shit

  • @MrRFPinhas

    @MrRFPinhas

    2 жыл бұрын

    @@uwufemboy5683 lol yeah

  • @lu_ck

    @lu_ck

    2 жыл бұрын

    @@uwufemboy5683 or you're dealing with bignums?

  • @DoorknobPlus

    @DoorknobPlus

    2 жыл бұрын

    @@uwufemboy5683 or if you are a bank

  • @Ownedyou
    @Ownedyou5 ай бұрын

    10 hour version of Fireship going "0000000000000000"!

  • @tradetor
    @tradetor10 ай бұрын

    the pain I had when I realized the reason my elastoplastic model failed is because matlab don't know how to add lol

  • @xrayian
    @xrayian3 жыл бұрын

    Toy language had me laughing till the end of the video

  • @collinthomas6288

    @collinthomas6288

    3 жыл бұрын

    the shade

  • @naveedalirehmani4135
    @naveedalirehmani41353 жыл бұрын

    "javascript is a toy language" oh God as a web Developer this hurts on a personal level but seriously talking I am a software engineer and a web developer and all the people who think it's a toy language need to go see a doctor

  • @joaomendoncayt

    @joaomendoncayt

    3 жыл бұрын

    you are so naive ='D

  • @TopBagon

    @TopBagon

    3 жыл бұрын

    Nah they need to go see sharp

  • @zeroww7

    @zeroww7

    3 жыл бұрын

    in the next scene he shows freaking python lmfao that is even more toy looking

  • @rmaster934

    @rmaster934

    3 жыл бұрын

    He was joking...? I mean, this channel does many cool Javascript stuff so...

  • @doober.43
    @doober.43 Жыл бұрын

    now I get why my game's countdown was like that

  • @kulgydudemanyo
    @kulgydudemanyo11 ай бұрын

    At least they're consistent!

  • @debapriyasinha11
    @debapriyasinha112 жыл бұрын

    When you forgot a float property in python 😂😂

  • @Antagon666
    @Antagon6662 жыл бұрын

    "JavaScript is a toy language." 'Proceeds to use another toy language.'

  • @fakegandhi5577

    @fakegandhi5577

    2 жыл бұрын

    Seriously, more people use JavaScript than python. Most computer users only use Microsoft programs, google chrome, and website scripts. That's where most of their program variety comes from.

  • @spongebobseyelashes8548
    @spongebobseyelashes85485 ай бұрын

    It’s cause of the IEEE754 floating point system. It calculates the sign, mantissa (basically the number represented between 0 and 1) and the exponent with bias. The issue arises with binary, as the calculation is ultimately done there. 0.3 and others will have rounding issues due to repeating patterns, so the computer isn’t able to precisely compute it. Therefore it does as good a job as it can with the mantissa bits, and then rounds the ending which is why you get the weird number at the end

  • @spongebobseyelashes8548

    @spongebobseyelashes8548

    5 ай бұрын

    I recognize he put this info in there but I legit took a 216 class this semester and number representations is a big part sorry

  • @salembendeck
    @salembendeck Жыл бұрын

    Computers may suck with this, but I'd like to see you do 15 digit by 15 digit problems in a nanosecond.

  • @raleo7466
    @raleo74662 жыл бұрын

    An explanation about IE^3 (IEEE 745) would be nice, to help people understand the math behind compressing big base10 number into binary

  • @zanehannan5306

    @zanehannan5306

    2 жыл бұрын

    There are plenty of those around, but the best ones take upwards of 10 minutes.

  • @zanehannan5306

    @zanehannan5306

    2 жыл бұрын

    Some end up covering how the fast inverse square root function works from Quake.

  • @fadious_padious2711
    @fadious_padious27112 жыл бұрын

    Hahaha. Hope you never have to deal with two systems that speak different floating point standards.

  • @Sakar0Z
    @Sakar0Z Жыл бұрын

    Lua devs: What's nine plus teen? Every other language: 21.0000000000000004

  • @Thrarm
    @Thrarm Жыл бұрын

    well when i go to google and type "0.1 + 0.1" and the built in calculator shows up it works fine

  • @MisterDan
    @MisterDan2 жыл бұрын

    When we designed the Sheerpower real data type we put the integer part of numbers into one memory location and the fractional part into another. That stopped the penny errors:) Of course Sheerpower is a computer language for business... so it was well worth the effort!

  • @zanehannan5306

    @zanehannan5306

    2 жыл бұрын

    So basically fixed point? Makes sense, if a little awkward. A good alternative is fixed point within the typesystem, but that takes time, effort, and compile time trickery to make it work no questions asked with little to no memory excess for storage.

  • @MisterDan

    @MisterDan

    2 жыл бұрын

    The developer does not change their code, so not awkward for them. Transindental functions, rarely used in business applications, are handled by the runtime engine converting to and from F64.

  • @MisterDan

    @MisterDan

    2 жыл бұрын

    It did take a year to support it all seamlessly.

  • @WorBlux

    @WorBlux

    Жыл бұрын

    The traditional approach is Binary coded Decimal, or BCD

  • @shanegrayson7068
    @shanegrayson70683 жыл бұрын

    @0:49 omfg, I remember using that site for my Architect course. Was super helpful.

  • @Fisk237
    @Fisk237 Жыл бұрын

    In C# you can choose if it's gonna be a float or an int

  • @Rinael22
    @Rinael222 жыл бұрын

    You literally have the best content for programmers, both entertaining both full of information. Thank you for all your efforts

  • @thecandybarbandit6887
    @thecandybarbandit68872 жыл бұрын

    Nobody’s gonna ask why he needed a calculator to solve that problem?

  • @ShiniestMeatManKrieg

    @ShiniestMeatManKrieg

    2 жыл бұрын

    Better question: why didn't he use a calculator app on bis computer ?

  • @KingTeravolt
    @KingTeravolt2 жыл бұрын

    Wonderful, fantastic, educational video! *Now if only I understood anything that was said*

  • @haim0z
    @haim0z Жыл бұрын

    Actually in C you can manually set the integers to doubles, long floats, and other floats to be way longer than languages like python and JavaScript

  • @designd9956
    @designd99562 жыл бұрын

    AKA floating point errors. Very annoying especially if your dealing with radians in video games. Don’t forget to put the dot in the end of your number when doing a math operation or declaring your variable as a float!

Келесі