Ruby 3.4 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Integerクラス > **
self ** other -> Numeric
[permalink][rdoc]pow(other) -> Numeric
pow(other, modulo) -> Integer
算術演算子。冪(べき乗)を計算します。
2 ** 3 # => 8
2 ** 0 # => 1
0 ** 0 # => 1
3.pow(3, 8) # => 3
3.pow(3, -8) # => -5
3.pow(2, -2) # => -1
-3.pow(3, 8) # => 5
-3.pow(3, -8) # => -3
5.pow(2, -8) # => -7
計算結果が巨大すぎるときは ArgumentError が発生します。
計算結果が巨大すぎる例
p 100**9999999999999999999
# => exponent is too large (ArgumentError)
判定の閾値は変わりえます。
[SEE_ALSO] BigDecimal#power