Is Multiplying the Inverse Better or Worse?

前端 未结 11 1165
忘了有多久
忘了有多久 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:29

    If you're dividing by a literal value like 645.16 then it's very likely that there is no difference because the compiler can easily determine which version is faster and use that.
    If you're dividing or multiplying by a variable then it's likely that multiplication is slightly faster because the logic is generally more simple.
    As with anything, to be sure, use a profiler.

提交回复
热议问题