50. Pow(x, n)

来源:互联网 发布:我的淘宝流量入口 编辑:程序博客网 时间:2024/06/03 17:09

1.换底公式

public class Solution {    public double myPow(double x, int n) {        int sign = 1;        if( x < 0 && n % 2 == 1){            sign = -1;        }        x = Math.abs(x);        return sign * Math.exp(n * Math.log(x));        }}

2.