Approximate e^x

前端 未结 10 2158
一向
一向 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:39

    First off, what is motivating this approximation? In other words, what exactly is wrong with the straightforward exp(x)?

    That said, a typical implementation of exp(x) is to

    • Find an integer k and floating point number r such that x=k*log(2) + r and r is between -0.5*log(2) and 0.5*log(2).
    • With this reduction, exp(x) is 2k*exp(r).
    • Calculating 2k is a snap.
    • The standard implementations of exp(x) use a Remes-type algorithm to come up with a minimax polynomial that approximates exp(r).
    • You could do the same, but use a reduced order polynomial.

    Here's the kicker: No matter what you do the odds are very high that your function will be much, much slower than just calling exp(). Most of the functionality of exp() is implemented in your computer's math coprocessor. Re-implementing that functionality in software, even with reduced precision, is going to be an order of magnitude slower than just using exp().

提交回复
热议问题