Floating point exponentiation without power-function

前端 未结 3 2090
长情又很酷
长情又很酷 2020-12-15 10:44

Currently I have to work in an environment where the power-operator is bugged. Can anyone think of a method temporarily work around this bug and compute a^b (both floating p

3条回答
  •  渐次进展
    2020-12-15 11:20

    You can use the identity ab = e(b log a), then all the calculations are relative to the same base e = 2.71828...

    Now you have to implement f(x) = ln(x), and g(x) = e^x. The fast, low precision method would be to use lookup tables for f(x) and g(x). Maybe that's good enough for your purposes. If not, you can use the Taylor series expansions to express ln(x) and e^x in terms of multiplication and addition.

提交回复
热议问题