Lemmy.eus
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 27 days ago

Floating point arithmetics

eviltoast.org

message-square
9
fedilink
1

Floating point arithmetics

eviltoast.org

orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 27 days ago
message-square
9
fedilink
alert-triangle
You must log in or # to comment.
  • gravitas_deficiency@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    27 days ago

    Look at what they need to mimic a fraction inaccurately.

    The fundamental mathematical nature of how binary floating point values are stored means that extremely straightforward and rational (in the mathematical sense of the term) base-10 arithmetic can surprisingly often yield results that are irrational (again, mathematically) in binary - hence why you’ll sometimes see a result of 3.000000000101325 or something like that in places where you’d expect the result to be simply 3.0

    • jjjalljs@ttrpg.network
      link
      fedilink
      arrow-up
      0
      ·
      27 days ago

      Yep. Open your browser’s console and do .1 + .2 and you get 0.30000000000000004.

      One of the reasons not to use floating point when working with money.

      • bamboo@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        0
        ·
        27 days ago

        What’s the right way to do money math without floats?

        • orhtej2@eviltoast.orgOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          27 days ago

          Fixed-point arithmetics

  • irelephant [he/him]@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    1
    ·
    26 days ago

    Eviltoasts pict-rs is being silly again

  • Grandwolf319@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    27 days ago

    Cause fractions can be figured out in context. You can store the numerators and have the denominator as a constant in the code.

    • Frezik@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      0
      ·
      27 days ago

      You can also have a type which does it. Raku has a Rational type for this.

      • Kacarott@aussie.zone
        link
        fedilink
        arrow-up
        1
        ·
        27 days ago

        Python has the Fraction type, and there are many more

      • dontsayaword@piefed.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        27 days ago

        Part of my first programming courses in the 90s in C were creating a native fraction type.

Programmer Humor@programming.dev

programmer_humor@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: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
Visibility: Public
globe

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

  • 1.03K users / day
  • 5.73K users / week
  • 5.87K users / month
  • 17.5K users / 6 months
  • 3 local subscribers
  • 27.2K subscribers
  • 1.66K Posts
  • 37.8K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.7
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org