Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/integer.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,10 @@ class Integer < Numeric
# a.pow(b) #=> same as a**b
# a.pow(b, m) #=> same as (a**b) % m, but avoids huge temporary values
#
def pow: (Integer other, ?Integer modulo) -> Integer
| (Float) -> Float
| (Rational) -> Rational
def pow: (Integer other) -> (Integer | Rational)
| (Integer other, Integer modulo) -> Integer
| (Float) -> (Float | Complex)
| (Rational) -> (Float | Rational | Complex)
| (Complex) -> Complex

# <!--
Expand Down
27 changes: 27 additions & 0 deletions test/stdlib/Integer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,30 @@ def test_try_convert
)
end
end

class IntegerInstanceTest < Test::Unit::TestCase
include TestHelper

testing "::Integer"

def test_pow
assert_send_type "(Integer) -> Integer",
1, :pow, 2
assert_send_type "(Integer) -> Rational",
-2, :pow, -1
assert_send_type "(Integer, Integer) -> Integer",
1, :pow, 2, 10
assert_send_type "(Float) -> Float",
1, :pow, 1.0
assert_send_type "(Float) -> Complex",
-9, :pow, 0.1
assert_send_type "(Rational) -> Float",
2, :pow, 1/2r
assert_send_type "(Rational) -> Rational",
1, :pow, 1r
assert_send_type "(Rational) -> Complex",
-3, :pow, -4/3r
assert_send_type "(Complex) -> Complex",
1, :pow, 1i
end
end