2
C-sucks
4y

me asking python: is (0.1 + 0.2) == 0.3 ?
python: NO
me: wha.!!
python: Instead, it's 0.30000000000000004
me: what the actual F***!!

Comments
  • 0
    @Demolishun I don't get it, mate. What decimal.
  • 1
    It's a floating point issue. There are several numbers which has no representation in binary so there are libraries in many languages which are facing this problem.

    https://docs.python.org/3/library/...
  • 1
    Use rounding tbh

    round (0.1 + 0.2, 3) == 0.3

    This will work just fine, no imports needed (decimal is an imported type)
  • 1
    "Python", and every other language with finite precision floating point accuracy numbers.
  • 1
    that's why you should understand hardware too, just knowing "python" doesn't make you a programmer.
  • 4
    Welcome to floats.

    Floats allow us to weed out juniors who don't understand decimal precision or how to read a manual.
  • 1
  • 2
    It works in C:

    #include <stdio.h>

    int main()

    {

    auto a=0.1;

    auto b=0.2;

    auto c=0.3;

    printf("%s\n",a+b==c?"True":"False");

    }

    Of course, the reason why it prints "True" has nothing to do with floating point precision.
  • 0
    @theabbie damn ,burned. You just RIP him.
  • 0
    Luckily you didn't ask this in Stackoverflow , otherwise you will be gnagband like you are in PornHub.
  • 0
    @happygimp0 but unfortunately his name suggests he hate C.
Add Comment