快速1 / X分频(倒数) [英] Fast 1/X division (reciprocal)

查看:114
本文介绍了快速1 / X分频(倒数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果精确度不重要,是否有某种方法可以改善相对于速度的倒数(除以1除以X)。

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

所以,我需要计算1 / X。有没有一些解决方法,所以我失去精度,但更快?

So, I need to calculate 1/X. Is there some workaround so I lose precision but do it faster?

推荐答案

首先,确保这不是一个过早优化。你知道这是你的瓶颈吗?

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

如Mystical所说,1 / x可以很快计算。请确保您未对1或除数使用 double 数据类型。浮动快得多。

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.

这就是说,基准,基准,基准。不要浪费你的时间花费数小时的理论,只是为了发现糟糕的性能的来源是IO访问。

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.

这篇关于快速1 / X分频(倒数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆