Ruby 3.4 リファレンスマニュアル

instance method Integer#**

self ** other -> Numeric[permalink][rdoc][edit]
pow(other) -> NumericRuby 2.5.0 から
pow(other, modulo) -> IntegerRuby 2.5.0 から

算術演算子。冪(べき乗)を計算します。

[PARAM] other:
二項演算の右側の引数(対象)
[PARAM] modulo:
指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
[RETURN]
計算結果
[EXCEPTION] TypeError:
2引数 powInteger 以外を指定した場合に発生します。
[EXCEPTION] RangeError:
2引数 powother に負の数を指定した場合に発生します。
[EXCEPTION] ArgumentError:
計算結果が巨大になりすぎる場合に発生します。
p 2 ** 3 # => 8
p 2 ** 0 # => 1
p 0 ** 0 # => 1
p 3.pow(3,  8)  # =>  3
p 3.pow(3, -8)  # => -5
p 3.pow(2, -2)  # => -1
p -3.pow(3,  8) # =>  5
p -3.pow(3, -8) # => -3
p 5.pow(2, -8)  # => -7

計算結果が巨大すぎるときは ArgumentError が発生します。

計算結果が巨大すぎる例
p 100**9999999999999999999
# => exponent is too large (ArgumentError)

判定の閾値は変わりえます。

[SEE_ALSO] BigDecimal#power