J2ME power(double, double) math function implementation

*爱你&永不变心* 提交于 2019-11-27 08:15:23

问题


I want to implement math function power to double, can you advice algorithm for this?

I've reviewed sources of Java ME Open Source Software - Math but I want to implement it from the scratch.

Thank you!


回答1:


I don't know J2ME well enough to know, but do you have Math.log() and Math.exp() ?

Then you can simply use this relation:

x^y = exp(y * log(x))

If you don't have the aforementioned two functions, then you should start by implementing those. As far as I know, the above relation is the only reasonable way to compute x^y.


Update: I see the paper linked in kusman's answer shows an alternative way to do pow using the idea of a fractional exponent. Quite cool! But the paper also shows the "normal" way to do things via multiplication of the log, and shows you how to implement Taylor series for exp() and log().



来源:https://stackoverflow.com/questions/2076913/j2me-powerdouble-double-math-function-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!