T
T
tyoma_koder2021-11-27 10:34:01
Algorithms
tyoma_koder, 2021-11-27 10:34:01

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

1 answer(s)
G
GlamorousCar, 2021-11-27
@GlamorousCar

Algorithm for finding the root of the nth degree

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question