2.9999999999999999 >> .5?

后端 未结 10 2162
悲&欢浪女
悲&欢浪女 2021-02-07 16:04

I heard that you could right-shift a number by .5 instead of using Math.floor(). I decided to check its limits to make sure that it was a suitable replacement, so I checked the

10条回答
  •  无人共我
    2021-02-07 16:18

    The shift right operator only operates on integers (both sides). So, shifting right by .5 bits should be exactly equivalent to shifting right by 0 bits. And, the left hand side is converted to an integer before the shift operation, which does the same thing as Math.floor().

提交回复
热议问题