English 中文(简体)
浮动点的快速替代方法
原标题:Quick alternatives to floating point multiplication to calculate percentages

I m 撰写一些关于Arduino的法典,该法典需要迅速运行,并对 in化的百分比进行粗略估计。

例如,鉴于我想要找到其中90%,即70%或30%。 这样做的明显方法是用浮动点g. x * 0.9;或x * 0.3;但由于我需要速度,我想避免计算浮动点。 如果我只是用两种力量分裂,那么我就进行双向转变,但是否有类似的技术可以接近90%、80%等使用惯犯?

问题回答

你们可以把拥有二分母权力的分数计算出这些百分比。

下面是<代码>2^16的简单例子:

90% = 90 / 100 ~ 58982 / 65536
70% = 70 / 100 ~ 45875 / 65536
30% = 30 / 100 ~ 19661 / 65536

 x% =  x / 100 ~ x * 655 / 65536

各司(现为两权)可以轮流进行。

当然,可以进行一些预先计算,以产生这些分数。





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签