本文介绍了重新排列方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的公式在我的C code
I have the following equation in my C code
k * dl * (1.0 + pHold / centre
+ (pHold * pHold) / (2.0 * centre * centre)
- square / (2.0 * centre))
我知道浮点部门是很多比乘法贵,而且我一直在这个搏斗了一会儿。有什么办法重新安排该切出一个部门?
I know that floating point divisions are a lot more expensive than multiplications, and I have been wrestling with this for a while. Is there any way to rearrange this to cut out a division?
感谢
推荐答案
如果你看一下分母你可以看到,做一个常用的单位将允许你做师只有一次(以更乘法为代价的分数):
If you look at the denominators for the fractions you can see that making a common denomination would allow you to do the division just once (at the expense of more multiplications):
k * dl * (1.0
+ pHold / (centre)
- square / (2.0 * centre)
+ (pHold * pHold) / (2.0 * centre * centre)
)
如果您确定浮点乘法比浮点除法则更好:
If you are sure that a floating point multiplication is better than a floating point division then:
k * dl * (1.0
+ (pHold * 2.0 * centre) / (2.0 * centre * centre)
- (square * centre) / (2.0 * centre * centre)
+ (pHold * pHold) / (2.0 * centre * centre)
)
这已经成为:
k * dl * (1.0
+ ( (pHold * 2.0 * centre)
- (square * centre)
+ (pHold * pHold) ) / (2.0 * centre * centre)
)
这篇关于重新排列方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!