Skip to content

isqrt? #245

Description

@angleKH

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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions