Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#pow

(::Integer other) -> (::Integer | ::Rational)
(::Integer other, ::Integer modulo) -> ::Integer
(::Float) -> (::Float | ::Complex)
(::Rational) -> (::Float | ::Rational | ::Complex)
(::Complex) -> ::Complex
integer.pow(numeric) → numeric
integer.pow(integer, integer) → integer

Returns (modular) exponentiation as:

Example
a.pow(b)     #=> same as a**b
a.pow(b, m)  #=> same as (a**b) % m, but avoids huge temporary values
See also #ord #pred #odd? #rationalize also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0