[removed] Calculate the nth root of a number

前端 未结 9 1447
长情又很酷
长情又很酷 2020-12-04 20:26

I\'m trying to get the nth root of a number using JavaScript, but I don\'t see a way to do it using the built in Math object. Am I overlooking something?
If

9条回答
  •  借酒劲吻你
    2020-12-04 21:08

    You could use

    Math.nthroot = function(x,n) {
        //if x is negative function returns NaN
        return this.exp((1/n)*this.log(x));
    }
    //call using Math.nthroot();
    

提交回复
热议问题