Unlemmy
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
irelephant [he/him]@programming.devM to Software Gore@programming.devEnglish · 8 days ago

pretty small subtotal.

message-square
26
link
fedilink
148

pretty small subtotal.

irelephant [he/him]@programming.devM to Software Gore@programming.devEnglish · 8 days ago
message-square
26
link
fedilink
  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    1
    arrow-down
    14
    ·
    7 days ago

    A f64 is a double, floating point precision type, aka not precise

    f64 is perfectly precise.

    The correct format to store money in? A string

    Lol ok.

    $3.99999999898998888181

    If only we had this thing called rounding…

    • Scrubbles@poptalk.scrubbles.tech
      link
      fedilink
      English
      arrow-up
      12
      ·
      7 days ago

      Double is not perfectly precise. It is quite literally a function that calculates what the value should be. There are converters to show the drift: https://www.h-schmidt.net/FloatConverter/IEEE754.html

      $40.01 is literally stored as 01000010001000000000101000111101 in a float type, which is literally stored as 40.009998321533203125. The margin of error goes up the larger the number.

      Either you’re just trolling, or incredibly arrogant. I have been coding in the FinTech space for over a decade and can tell you firsthand that these are real issues, and have real consequences.

      But hey, don’t take my word for it:

      • https://dzone.com/articles/never-use-float-and-double-for-monetary-calculatio
      • https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types#characteristics-of-the-floating-point-types
      • https://swiftbydeya.com/never-use-floating-point-double-data-types-for-monetary-calculations/
      • https://www.slingacademy.com/article/handling-currency-and-financial-calculations-with-javascript-numbers/

      There have been some famous disasters thanks to floating point math

      • The story of Ariane 5
      • How a Minor Calculation Error Cost Intel Half a Billion Dollars
      • Wikipedia

      As for rounding, I can’t even think of a way to describe what a terrible idea that is. I’d suggest reading those articles and asking the stock exchange why they don’t “just round it” when dealing with millions of transactions that deal with fractions of pennies. “Just round it”

      • funkless_eck@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        6 days ago

        re your last point: or just watch Superman III.

        • Scrubbles@poptalk.scrubbles.tech
          link
          fedilink
          English
          arrow-up
          3
          ·
          6 days ago

          or office space!

      • FizzyOrange@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        6 days ago

        Double is not perfectly precise. It is quite literally a function that calculates what the value should be. There are converters to show the drift: https://www.h-schmidt.net/FloatConverter/IEEE754.html

        $40.01 is literally stored as 01000010001000000000101000111101 in a float type, which is literally stored as 40.009998321533203125. The margin of error goes up the larger the number.

        No you’re fundamentally misunderstanding what’s going on. Float isn’t “storing 40.01 but imprecisely”. That’s like saying an integer “stores 1.1 but imprecisely”. Floating point can’t represent the number 40.01. But that doesn’t matter because 4.0009999999999998 is easily accurate enough for any real world use.

        The story of Ariane 5

        This was caused by converting an f64 to i16 which caused an overflow and hardware exception. Irrelevant.

        How a Minor Calculation Error Cost Intel Half a Billion Dollars

        Hardware bug. Irrelevant.

        Wikipedia

        Literally says “The failure to intercept arose not from using floating point specifically”

        and asking the stock exchange

        I’m not talking about stock exchanges. Obviously they have extreme requirements. For most normal businesses and people f64 is fine.

        You’re repeating dogma without thinking about it.

    • I_am_10_squirrels@beehaw.org
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      6 days ago

      Have you seen office space?

Software Gore@programming.dev

software_gore@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !software_gore@programming.dev

A community for posting software malfunctions

Deliberately bad software or bad design is not software gore, it must be something unintentional

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient and shear it



Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1 user / day
  • 101 users / week
  • 213 users / month
  • 349 users / 6 months
  • 1 local subscriber
  • 1.18K subscribers
  • 53 Posts
  • 63 Comments
  • Modlog
  • mods:
  • irelephant [he/him]@programming.dev
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org