From c6296c023231fe3489c10de585219db312c13605 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 25 Jun 2024 14:20:16 +0900 Subject: [PATCH 1/2] Fix double-splat --- Gemfile.lock | 2 +- Rakefile | 2 +- core/complex.rbs | 5 ++++- core/float.rbs | 6 ++++-- core/integer.rbs | 6 +++--- core/rational.rbs | 6 ++++-- stdlib/bigdecimal/0/big_decimal.rbs | 5 ++++- test/raap.txt | 5 +++++ 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 031ca8ba0..d9a4ce0d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,7 +71,7 @@ GEM psych (4.0.6) stringio public_suffix (6.0.0) - raap (0.8.0) + raap (0.10.0) rbs (~> 3.0) timeout (~> 0.4) racc (1.8.0) diff --git a/Rakefile b/Rakefile index f4561e93e..a6f6c31f3 100644 --- a/Rakefile +++ b/Rakefile @@ -106,7 +106,7 @@ task :typecheck_test => :compile do end task :raap => :compile do - sh %q[cat test/raap.txt | egrep -v '^#|^$' | xargs bundle exec raap] + sh %q[cat test/raap.txt | egrep -v '^#|^$' | xargs bundle exec raap --require bigdecimal/util --library bigdecimal] end task :rubocop do diff --git a/core/complex.rbs b/core/complex.rbs index b251a051b..dd3885465 100644 --- a/core/complex.rbs +++ b/core/complex.rbs @@ -134,7 +134,10 @@ class Complex < Numeric # Complex('i') ** 2 # => (-1+0i) # Complex(-8) ** Rational(1, 3) # => (1.0000000000000002+1.7320508075688772i) # - def **: (Numeric) -> Complex + def **: (Integer) -> Complex + | (Float) -> Complex + | (Rational) -> Complex + | (Complex) -> Complex # + # Raises `self` to the power of `numeric`: + # + # 2 ** 3 # => 8 + # 2 ** -3 # => (1/8) + # -2 ** 3 # => -8 + # -2 ** -3 # => (-1/8) + # 2 ** 3.3 # => 9.849155306759329 + # 2 ** Rational(3, 1) # => (8/1) + # 2 ** Complex(3, 0) # => (8+0i) + # + def **: (BigDecimal) -> BigDecimal + | ... end %a{annotate:rdoc:skip} @@ -1584,6 +1601,22 @@ class Float # def -: (BigDecimal) -> BigDecimal | ... + + # + # Raises `self` to the power of `other`: + # + # f = 3.14 + # f ** 2 # => 9.8596 + # f ** -2 # => 0.1014239928597509 + # f ** 2.1 # => 11.054834900588839 + # f ** Rational(2, 1) # => 9.8596 + # f ** Complex(2, 0) # => (9.8596+0i) + # + def **: (BigDecimal) -> BigDecimal + | ... end %a{annotate:rdoc:skip} @@ -1687,6 +1720,22 @@ class Rational # def -: (BigDecimal) -> BigDecimal | ... + + # + # Performs exponentiation. + # + # Rational(2) ** Rational(3) #=> (8/1) + # Rational(10) ** -2 #=> (1/100) + # Rational(10) ** -2.0 #=> 0.01 + # Rational(-4) ** Rational(1, 2) #=> (0.0+2.0i) + # Rational(1, 2) ** 0 #=> (1/1) + # Rational(1, 2) ** 0.0 #=> 1.0 + # + def **: (BigDecimal) -> (Rational | BigDecimal) + | ... end %a{annotate:rdoc:skip} @@ -1771,6 +1820,18 @@ class Complex # def -: (BigDecimal) -> Complex | ... + + # + # Returns `self` raised to power `numeric`: + # + # Complex('i') ** 2 # => (-1+0i) + # Complex(-8) ** Rational(1, 3) # => (1.0000000000000002+1.7320508075688772i) + # + def **: (BigDecimal) -> Complex + | ... end %a{annotate:rdoc:skip}