Answer the question
In order to leave comments, you need to log in
How to find the root of any number in any base?
I found such a code, but for the root of the 4th degree of 8 it freezes
function sqrt(a, b) {
if(b<2) return a
let num = a;
let rootDegree = b;
let eps = 0.00001; //допустимая погрешность
let root = num / rootDegree; //начальное приближение корня
let rn = num; //значение корня последовательным делением
while(Math.abs(root - rn) >= eps){
rn = num;
for(let i = 1; i < rootDegree; i++){
rn = rn / root;
}
root = 0.5 * ( rn + root);
}
return root;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question