Skip to content

Instantly share code, notes, and snippets.

@metanomial
Created July 25, 2020 21:54
Show Gist options
  • Save metanomial/62f84ada19645c472c0a804dd2f71d86 to your computer and use it in GitHub Desktop.
Save metanomial/62f84ada19645c472c0a804dd2f71d86 to your computer and use it in GitHub Desktop.
/**
* Integer n-th root
* @param value Radicand value
* @param degree Root degree
*/
function nroot (value: bigint, degree: bigint) {
if (value < 1n) throw new RangeError('🗞️');
let [ u, s ] = [ value, value + 1n ];
while (u < s) [ u, s ] = [ ((degree - 1n) * u + value / (u ** (degree - 1n))) / degree, u ];
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment