有效执行自然对数(ln)和取幂 [英] Efficient implementation of natural logarithm (ln) and exponentiation

查看:134
本文介绍了有效执行自然对数(ln)和取幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在寻找C库<math.h>中提供的log()exp()函数的实现.我正在使用8位微控制器(OKI 411和431).我需要计算平均运动温度.要求是我们应该能够尽可能快地计算MKT,并使用尽可能少的代码存储器.编译器在<math.h>中带有log()exp()函数.但是调用任何一个函数并与库链接都会导致代码大小增加5 KB,这不适合我们使用的微控制器之一(OKI 411),因为我们的代码已经消耗了大约12K的可用〜15K代码内存.

Basically, I'm looking for implementation of log() and exp() functions provided in C library <math.h>. I'm working with 8 bit microcontrollers (OKI 411 and 431). I need to calculate Mean Kinetic Temperature. The requirement is that we should be able to calculate MKT as fast as possible and with as little code memory as possible. The compiler comes with log() and exp() functions in <math.h>. But calling either function and linking with the library causes the code size to increase by 5 Kilobytes, which will not fit in one of the micro we work with (OKI 411), because our code already consumed ~12K of available ~15K code memory.

我正在寻找的实现不应使用任何其他C库函数(例如pow(),sqrt()等).这是因为所有库函数都打包在一个库中,即使调用了一个函数,链接器也会将整个5K库带到代码存储器中.

The implementation I'm looking for should not use any other C library functions (like pow(), sqrt() etc). This is because all library functions are packed in one library and even if one function is called, the linker will bring whole 5K library to code memory.

编辑

该算法的正确性应小数点后3位.

The algorithm should be correct upto 3 decimal places.

推荐答案

e ^ x的泰勒级数收敛非常快,您可以将实现调整到所需的精度. ( http://en.wikipedia.org/wiki/Taylor_series )

The Taylor series for e^x converges extremely quickly, and you can tune your implementation to the precision that you need. (http://en.wikipedia.org/wiki/Taylor_series)

泰勒原木系列不那么好...

The Taylor series for log is not as nice...

这篇关于有效执行自然对数(ln)和取幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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