Today I learned that -Infinity >> 0 = 0

  • 0
    You're Right
  • 2
    >> is on integer values
    !isfinite are converted to 0 per the standard

    I don’t see the problem 👀
  • 2
    @penless No issue. I just didn’t realize that it coerced values to INT32 before bitwise operations
  • 1
    @AmyShackles I mean it's pretty hard to define shifts on floats.
    What it could do is to convert it to INT_MIN, as they have an identical purpose.
  • 0
    I don't get why people think this is undefined behavior. MDN docs literally explain this specific case.
  • 0
    @hashedram It isn't undefined behavior, it's stupid behavior. The smallest float possible should convert to the smallest integer possible, because both are primarily used as initial value for algorithms.
  • 0
    @homo-lorens something something I'm not used to dynamic typing so I'll moan about it
  • 0
    @hashedram My axioms:
    Javascript doesn't let you explicitly specify types
    -infinity has the same role as INT_MIN
    My reasoning:
    Because they have the same role, casting -infinity to INT_MIN would be the least disruptive.
    Because javascript doesn't let you explicitly specify types, it doesn't expect you to keep track of the distinction between ints and floats
    Because you aren't expected to know when a cast happens, it's best if the casts are the least disruptive possible.
Add Comment