Fast 1/X division (reciprocal)

后端 未结 6 1282
忘掉有多难
忘掉有多难 2020-12-29 22:46

Is there some way to improve reciprocal (division 1 over X) with respect to speed, if the precision is not crucial?

So, I need to calculate 1/X. Is there so

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 23:35

    First, make sure this isn't a case of premature optimization. Do you know that this is your bottleneck?

    As Mystical says, 1/x can be calculated very quickly. Make sure you're not using double datatype for either the 1 or the divisor. Floats are much faster.

    That said, benchmark, benchmark, benchmark. Don't waste your time spending hours on numerical theory just to discover the source of the poor performance is IO access.

提交回复
热议问题