[removed] Calculate the nth root of a number

前端 未结 9 1451
长情又很酷
长情又很酷 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:24

    The nth root of x is the same as x to the power of 1/n. You can simply use Math.pow:

    var original = 1000;
    var fourthRoot = Math.pow(original, 1/4);
    original == Math.pow(fourthRoot, 4); // (ignoring floating-point error)
    

提交回复
热议问题