Understanding Floating Point Struggles in 7 Minutes or Less

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 38

  • @johnbarbero757
    @johnbarbero757 ปีที่แล้ว +4

    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.

  • @darrenphillips1845
    @darrenphillips1845 ปีที่แล้ว +37

    It's a wonder we didn't shoot right past the moon.

    • @zane812
      @zane812 ปีที่แล้ว +5

      never went

    • @darrenphillips1845
      @darrenphillips1845 ปีที่แล้ว +2

      @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 ปีที่แล้ว

      @@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

    • @Ðogecoin
      @Ðogecoin ปีที่แล้ว

      To the moon! 🚀 🌝 Playboi carti 2024 album upcoming

    • @baileyharrison1030
      @baileyharrison1030 ปีที่แล้ว +4

      @@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’.

  • @OddMathisen
    @OddMathisen ปีที่แล้ว +1

    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. ❤

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว

    Great seeing a visual breakdown of the memory and the walkthrough for the problem!

  • @repairstudio4940
    @repairstudio4940 ปีที่แล้ว

    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...🎉

  • @shadowpenguin3482
    @shadowpenguin3482 ปีที่แล้ว +1

    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.

  • @ecavero1
    @ecavero1 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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

  • @C4rb0neum
    @C4rb0neum ปีที่แล้ว

    Amazing quality video! It’s clear that you have skills

  • @nepp9574
    @nepp9574 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      Yes so this was the way I taught it in my binary video in description.

  • @mechjack
    @mechjack ปีที่แล้ว +1

    I've seen math programs such as mathcad keep floating point numbers as fractions of whole numbers, i believe to fix this very problem
    .

  • @KontrolStyle
    @KontrolStyle ปีที่แล้ว

    we love some engineer man 8)

  • @alankoester3344
    @alankoester3344 ปีที่แล้ว

    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?

  • @ndbass09
    @ndbass09 ปีที่แล้ว

    Love your videos. Keep it up!

  • @lyshaka
    @lyshaka ปีที่แล้ว +2

    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);
    }

  • @PrivateUsername
    @PrivateUsername ปีที่แล้ว

    Maybe add in a bit about ULP? That could help with understanding why you get .30000004 vs .30000012 or whatnot.

  • @MisterDan
    @MisterDan 7 หลายเดือนก่อน

    Very nice video BTW.

  • @binbashbuddy
    @binbashbuddy ปีที่แล้ว +3

    Well explained. I've never been the first commenter before.

    • @EngineerMan
      @EngineerMan  ปีที่แล้ว +2

      First time for everything!

  • @esra_erimez
    @esra_erimez ปีที่แล้ว +1

    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"

  • @utekk
    @utekk ปีที่แล้ว

    Thx man

  • @simonmaracine4721
    @simonmaracine4721 ปีที่แล้ว

    👍

  • @OneOfThePetes
    @OneOfThePetes ปีที่แล้ว

    PowerShell 7 returns 0.3

  • @rebel478
    @rebel478 ปีที่แล้ว +1

    Bro please tell me why is your right eyebrow always higher

    • @0xDEAD-C0DE
      @0xDEAD-C0DE ปีที่แล้ว

      None of your business man.

    • @kkd0099
      @kkd0099 ปีที่แล้ว

      wtf are u talking about

    • @ZacKoch
      @ZacKoch ปีที่แล้ว

      It's because he's on sus looking at your comment 😂 - don't be a d!