Skip to content

Commit

Permalink
Merge pull request #1706 from ksss/integer-pow
Browse files Browse the repository at this point in the history
Fix Integer#pow signature
  • Loading branch information
soutaro authored Jan 9, 2024
2 parents 56afe36 + ffaca43 commit 0391fe6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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

0 comments on commit 0391fe6

Please sign in to comment.