summaryrefslogtreecommitdiff
path: root/spec/ruby/core
diff options
context:
space:
mode:
authorYusuke Endoh <[email protected]>2024-11-08 14:46:35 +0900
committerYusuke Endoh <[email protected]>2024-11-08 19:48:56 +0900
commit45cd4a8296814f3b082dfb906cdef29974726731 (patch)
treef0bb06b401fd95c09e9b44281473fafe5621c67b /spec/ruby/core
parentf7b334e002eba25e386917337771b65bed5297f8 (diff)
Do not round `a**b` to infinity
... instead, just calculate the value unless it is too big. Also, this change raises an ArgumentError if it is expected to exceed 16 GB in a 64-bit environment. (It is possible to calculate it straightforward, but it would likely be out-of-memory, so I didn't think it would make sense.) [Feature #20811]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12033
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/integer/shared/exponent.rb40
1 files changed, 29 insertions, 11 deletions
diff --git a/spec/ruby/core/integer/shared/exponent.rb b/spec/ruby/core/integer/shared/exponent.rb
index 15df518b7e..5ef6d686d8 100644
--- a/spec/ruby/core/integer/shared/exponent.rb
+++ b/spec/ruby/core/integer/shared/exponent.rb
@@ -48,10 +48,18 @@ describe :integer_exponent, shared: true do
(-1).send(@method, 4611686018427387905).should eql(-1)
end
- it "returns Float::INFINITY when the number is too big" do
- -> {
- 2.send(@method, 427387904).should == Float::INFINITY
- }.should complain(/warning: in a\*\*b, b may be too big/)
+ ruby_version_is ""..."3.4" do
+ it "returns Float::INFINITY when the number is too big" do
+ -> {
+ 2.send(@method, 427387904).should == Float::INFINITY
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError when the number is too big" do
+ -> { 100000000.send(@method, 1000000000) }.should raise_error(ArgumentError)
+ end
end
it "raises a ZeroDivisionError for 0 ** -1" do
@@ -108,13 +116,23 @@ describe :integer_exponent, shared: true do
-> { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
end
- it "switch to a Float when the values is too big" do
- flt = nil
- -> {
- flt = @bignum.send(@method, @bignum)
- }.should complain(/warning: in a\*\*b, b may be too big/)
- flt.should be_kind_of(Float)
- flt.infinite?.should == 1
+ ruby_version_is ""..."3.4" do
+ it "switch to a Float when the values is too big" do
+ flt = nil
+ -> {
+ flt = @bignum.send(@method, @bignum)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ flt.should be_kind_of(Float)
+ flt.infinite?.should == 1
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "does not switch to a Float when the values is too big" do
+ -> {
+ @bignum.send(@method, @bignum)
+ }.should raise_error(ArgumentError)
+ end
end
it "returns a complex number when negative and raised to a fractional power" do