-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer root algorithm #13416
Comments
See also #8920 |
I played around with this version for
They all create correct results when
As you can see Finally, I had to do all these
|
lib LibGMP
fun root = __gmpz_root(rop : MPZ*, op : MPZ*, n : ULong) : Int
end
def iroot(n : BigInt, p : Int::Primitive)
# error handling / range check not shown
BigInt.new { |mpz| LibGMP.root(mpz, n, p) }
end
iroot(15625.to_big_i, 6) # => 5.to_big_i
iroot(2187.to_big_i, 7) # => 3.to_big_i Invalid arguments should raise instead of returning |
I like this version better.
This works for all In doing some cursory timings (not benchmarks), this seems just as fast for |
This hack (which is not too ugly) will get around the lack of
|
Feature Request
While building a library, I recently needed a generic
iroot
method, while the stdlib currently only has anisqrt
method.This is the implementation I created using this article:
I'd like to ask whether an algorithm like this is considered important enough to be included in the stdlib.
The text was updated successfully, but these errors were encountered: