Is Multiplying the Inverse Better or Worse?

前端 未结 11 1206
忘了有多久
忘了有多久 2020-12-20 13:52

When dealing with double data types is multiplying by the inverse better or worse?

Which way is faster? Which way uses

11条回答
  •  感动是毒
    2020-12-20 14:20

    The benefit will be very small or zero, depending on both the compiler and the hardware.

    But it could still matter (in a tight loop), and then for readability you should write

    SquareInches = MMSquared * (1 / 645.16)
    

    And preferably use a constant for 645.16.

提交回复
热议问题