2.9999999999999999 >> .5?

后端 未结 10 2168
悲&欢浪女
悲&欢浪女 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:26

    And to add to John's answer, the odds of this being more performant than Math.floor are vanishingly small.

    I don't know if JavaScript uses floating-point numbers or some kind of infinite-precision library, but either way, you're going to get rounding errors on an operation like this -- even if it's pretty well defined.

提交回复
热议问题