Class
Constants
The version of loaded GMP.
Class Methods
2.5
View on GitHub
# File tmp/rubies/ruby-2.5.9/lib/prime.rb, line 49
def Integer.each_prime(ubound, &block) # :yields: prime
Prime.each(ubound, &block)
end
Iterates the given block over all prime numbers.
See Prime#each for more details.
2.5
View on GitHub
# File tmp/rubies/ruby-2.5.9/lib/prime.rb, line 22
def Integer.from_prime_division(pd)
Prime.int_from_prime_division(pd)
end
Re-composes a prime factorization and returns the product.
See Prime#int_from_prime_division for more details.
2.5
View on GitHub
static VALUE
rb_int_s_isqrt(VALUE self, VALUE num)
{
unsigned long n, sq;
num = rb_to_int(num);
if (FIXNUM_P(num)) {
if (FIXNUM_NEGATIVE_P(num)) {
domain_error("isqrt");
}
n = FIX2ULONG(num);
sq = rb_ulong_isqrt(n);
return LONG2FIX(sq);
}
else {
size_t biglen;
if (RBIGNUM_NEGATIVE_P(num)) {
domain_error("isqrt");
}
biglen = BIGNUM_LEN(num);
if (biglen == 0) return INT2FIX(0);
#if SIZEOF_BDIGIT <= SIZEOF_LONG
/* short-circuit */
if (biglen == 1) {
n = BIGNUM_DIGITS(num)[0];
sq = rb_ulong_isqrt(n);
return ULONG2NUM(sq);
}
#endif
return rb_big_isqrt(num);
}
}
Returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n.
Integer.sqrt(0) #=> 0 Integer.sqrt(1) #=> 1 Integer.