Why is multiplying cheaper than dividing?

后端 未结 3 1487
小鲜肉
小鲜肉 2021-02-15 16:03

I recently wrote a Vector 3 class, and I submitted my normalize() function for reviewal to a friend. He said it was good, but that I should multiply by the reciprocal where poss

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-15 16:21

    If you think back to grade school, you'll recall that multiplication was harder than addition and division was harder than multiplication. Things aren't any different for the CPU.

    Recall also that calculating the reciprocal involves a division, so unless you calculate the reciprocal once and use it three times, you won't see a speed up.

提交回复
热议问题