Skip to content

Commit bb48d27

Browse files
authored
Merge pull request #2927 from kyanagi/fix_too_big_a_pow_b
`Integer#**`, `Rational#**`が`Infinity`を返さなくなった変更に対応
2 parents 4ab8023 + 03331f5 commit bb48d27

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

refm/api/src/_builtin/Integer

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ self を other で割り、その(剰余を考えない)商を整数に切り上
732732
@return 計算結果
733733
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
734734
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。
735+
#@since 3.4
736+
@raise ArgumentError 計算結果が巨大になりすぎる場合に発生します。
737+
#@end
735738

736739
#@samplecode
737740
2 ** 3 # => 8
@@ -745,6 +748,7 @@ self を other で割り、その(剰余を考えない)商を整数に切り上
745748
5.pow(2, -8) # => -7
746749
#@end
747750

751+
#@until 3.4
748752
結果が巨大すぎる整数になりそうなとき、警告を出したうえで Float::INFINITY を返します。
749753

750754
#@samplecode 計算を放棄して Float::INFINITY を返す例
@@ -754,6 +758,18 @@ p 100**9999999
754758
#@end
755759

756760
判定の閾値は変わりえます。
761+
#@end
762+
763+
#@since 3.4
764+
計算結果が巨大すぎるときは ArgumentError が発生します。
765+
766+
#@samplecode 計算結果が巨大すぎる例
767+
p 100**9999999999999999999
768+
# => exponent is too large (ArgumentError)
769+
#@end
770+
771+
判定の閾値は変わりえます。
772+
#@end
757773

758774
@see [[m:BigDecimal#power]]
759775

refm/api/src/_builtin/Rational

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ r * Rational(1, 2) # => (3/8)
4545
冪(べき)乗を計算します。
4646

4747
@param other 自身を other 乗する数
48+
#@since 3.4
49+
@raise ArgumentError 計算結果の分母・分子が巨大すぎる場合に発生します。
50+
#@end
4851

4952
other に [[c:Float]] を指定した場合は、計算結果を [[c:Float]] で返しま
5053
す。other が有理数であっても、計算結果が無理数だった場合は [[c:Float]]

0 commit comments

Comments
 (0)