-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Description
I see that in a couple of other issues (#77, #73) a sqrt function was rejected because of ambiguity. What about an isqrt method for integer square root? It's unambiguous and returns an integer. Considering this library implements division with divide (which is really integer division), shouldn't an isqrt method be fine as well?
Example of a function that takes in a bigint from this library and returns a bigint of the integer square root, might not be the best performing algorithm but useful for just getting the feature working.
function bigInt_isqrt(n) {
let a = n;
let b = n.add(1).divide(2);
while (b.lt(a)) {
a = b;
b = (a.square().add(n)).divide(a.times(2));
}
return a;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels