小编Ale*_*ger的帖子

自然对数 (ln) 和幂的实现问题

我尝试遵循“自然对数 (ln) 和指数的有效实现”主题,以便能够在没有 math.h 的情况下实现对数函数。所描述的算法对于 1 到 2 之间的值(标准化值)效果很好。但是,如果这些值未标准化并且我遵循标准化说明,那么我会得到错误的值。

链接:点击这里

如果我按照示例整数值 12510 执行代码,我会得到以下结果:

y = 12510 (0x30DE),log2 = 13,除数 = 26,x = 481,1538

float ln(float y) {
    int log2;
    float divisor, x, result;

    log2 = msb((int)y); // See: /sf/answers/347960161/
    divisor = (float)(1 << log2);
    x = y / divisor;    // normalized value between [1.0, 2.0]

    result = -1.7417939 + (2.8212026 + (-1.4699568 + (0.44717955 - 0.056570851 * x) * x) * x) * x;
    result += ((float)log2) * 0.69314718; …
Run Code Online (Sandbox Code Playgroud)

c microcontroller natural-logarithm

3
推荐指数
1
解决办法
430
查看次数

标签 统计

c ×1

microcontroller ×1

natural-logarithm ×1