本文介绍了嵌入式处理器的快速斜边算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种聪明/有效的算法来确定角度的斜边(即 sqrt(a² + b²)),在嵌入式处理器上使用定点数学,无需硬件乘法?

Is there a clever/efficient algorithm for determining the hypotenuse of an angle (i.e. sqrt(a² + b²)), using fixed point math on an embedded processor without hardware multiply?

推荐答案

除非您以 >1kHz 的频率执行此操作,否则即使在没有硬件 MUL 的 MCU 上进行乘法也并不可怕.更糟糕的是 sqrt.我会尝试修改我的应用程序,使其根本不需要计算.

Unless you're doing this at >1kHz, multiply even on a MCU without hardware MUL isn't terrible. What's much worse is the sqrt. I would try to modify my application so it doesn't need to calculate it at all.

如果您确实需要标准库,它可能是最好的,但您可以考虑使用牛顿法作为一种可能的替代方法.然而,它需要几个乘法/除法周期才能执行.

Standard libraries would probably be best if you actually need it, but you could look at using Newton's method as a possible alternative. It would require several multiply/divide cycles to perform, however.

  • Atmel App note AVR200: Multiply and Divide Routines (pdf)
  • This sqrt function on AVR Freaks forum
  • Another AVR Freaks post

这篇关于嵌入式处理器的快速斜边算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 01:23