Efficient implementation of natural logarithm (ln) and exponentiation

后端 未结 8 2394
借酒劲吻你
借酒劲吻你 2020-12-15 09:18

I\'m looking for implementation of log() and exp() functions provided in C library . I\'m working with 8 bit microcontro

8条回答
  •  被撕碎了的回忆
    2020-12-15 09:41

    The log function can be implemented with O(1)

    First, let's make use of logn(x) = ln(x)/ln(n). ln(x) can be expressed as (x^h-1)/h, where h approaches 0. You can derive this with the differential quotient.

    float log(x, n) {
        return ((x^h-1)/h)/((n^h-1)/h)
    }
    

    So now choose a small value for h, it gets more accurate as you make it smaller. Constant runtime and small code size, I always prefer this method.

提交回复
热议问题