Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Exponentiation is done through repeated squaring, e.g.

    x^21 = x^16 * x^4 * x
    ...   = (((x^2)^2)^2)^2 * (x^2)^2 * x
Integer square roots can be done using binary search, which is O(n) for an n-bit number, but Newton's method can be used and it's usually much faster.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: