you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 10 months ago (4 children)

But of course -- It's just flipping around the -= operator!

  • source
  • parent
  • hideshow 4 child comments
  • [–] 3 points 10 months ago (2 children)

    Nope, it is not.

    x = 5
    i = 2
    x -= i // x => 3
    

    while

    x = 5
    i = 2
    x = -i // x => -2
    

    x=-i is the unary minus operator which negates the value right of it. It doesn't matter if that value is a literal (-3), a variable (-i) or a function (-f()).

    x-=i is short for x = x-i, and here it's a binary subtraction, so x is set to the result of i subtracted from x.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 10 months ago (1 child)

    I need to append /s to my future silly replies I think... that said, I'll never pooh-pooh a well thought response, so thanks for the nice write-up!

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 10 months ago*

    Thanks, I totally missed your sarcasm :)

    There's a couple people in this threat who seem to actually think that x = -i is some weird magic instead of a standard feature that's present in every major programming language.

  • source
  • parent