Approximate e^x

前端 未结 10 2137
一向
一向 2020-12-13 16:28

I\'d like to approximate the ex function.

Is it possible to do so using multiple splines type based approach? i.e between x1

10条回答
  •  情话喂你
    2020-12-13 16:57

    How about a strategy like this that uses the formula

    ex = 2 x/ln(2)

    1. Precalculate 1/ln(2)
    2. Multiply this constant by your argument (1 multiplication)
    3. Use binary shifts to raise 2 to the integer portion of the power (assumes exp+mantissa format)
    4. Adjust based on the fractional power-of-2 remainder (likely a second multiplication)

    I realize this is not a complete solution, but it does only require a single multiplication and reduces the remaining problem to approximating a fractional power of 2, which should be easier to implement in hardware.

    Also, if your application is specialized enough, you could try to re-derive all of the numerical code that will run on your hardware to be in a base-e number system and implement your floating point hardware to work in base e as well. Then no conversion is needed at all.

提交回复
热议问题