A solution to floating point errors

Sdílet
Vložit
  • čas přidán 25. 07. 2024
  • A quick solution to fixing floating point rounding errors without the need for BigDecimal

Komentáře • 17

  • @shivangsingh2463
    @shivangsingh2463 Před rokem

    Are you using python?

    • @plasma8321
      @plasma8321  Před rokem

      No. This is written in java. But the idea is the same

  • @justcurious1940
    @justcurious1940 Před rokem

    can u try this rounding method with 0.3 + 0.1 ? it does not work with me but it does work with 0.1 + 0.2
    i don't think this rounding technique solve the problem 🙃

    • @justcurious1940
      @justcurious1940 Před rokem

      sorry maybe i did not get the video are u rounding the stored value or just the output ?

    • @plasma8321
      @plasma8321  Před rokem

      @@justcurious1940 the output is rounded

    • @justcurious1940
      @justcurious1940 Před rokem

      @@plasma8321 well i used c++ and i have used a rounding function called std::round() I'm sure it works like the one u used in the video and guess what
      0.4 will always gives 0.40000000000000002

    • @plasma8321
      @plasma8321  Před rokem

      @@justcurious1940 This is weird. C++ seems to round both functions automatically without even needing to do anything. Im not sure how your getting this

    • @justcurious1940
      @justcurious1940 Před rokem

      @@plasma8321 std::cout.precision(17) ;
      std::cout

  • @justcurious1940
    @justcurious1940 Před rokem

    u sound so bored and not interested at all is java the reason ?

    • @plasma8321
      @plasma8321  Před rokem +1

      No! I was reading a script

    • @justcurious1940
      @justcurious1940 Před rokem +2

      ​@@plasma8321 its funny i'm using c++ and when i do something like this :
      double x = 0.3 ;
      std::cout