From ebab66df2d310481123a8d6ffc6f7d21c04190cc Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 28 Dec 2024 10:30:29 +0100 Subject: [PATCH 1/2] Update descriptions for rational exponent for Ruby 3.4 These were copied from the pre-3.4-version, and not updated for the behaviour change. --- shared/rational/exponent.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/rational/exponent.rb b/shared/rational/exponent.rb index 2145d6bace..758bc1e376 100644 --- a/shared/rational/exponent.rb +++ b/shared/rational/exponent.rb @@ -150,7 +150,7 @@ end ruby_version_is "3.4" do - it "returns positive Infinity when self < -1" do + it "raises an ArgumentError when self < -1" do -> { (Rational(-2) ** bignum_value) }.should raise_error(ArgumentError) @@ -159,7 +159,7 @@ }.should raise_error(ArgumentError) end - it "returns 0.0 when self is < -1 and the exponent is negative" do + it "raises an ArgumentError when self is < -1 and the exponent is negative" do -> { (Rational(-2) ** -bignum_value) }.should raise_error(ArgumentError) From ee02be4a47359adb2980f82439437e9b68e8430d Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 28 Dec 2024 10:38:53 +0100 Subject: [PATCH 2/2] Move non-linux specs for Rational exponents with ArgumentErrors The check for ArgumentError is performed within Ruby itself, and unrelated to bugs in pow() in glibc. These specs should run on Linux too. --- shared/rational/exponent.rb | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/shared/rational/exponent.rb b/shared/rational/exponent.rb index 758bc1e376..30ebf8d9b9 100644 --- a/shared/rational/exponent.rb +++ b/shared/rational/exponent.rb @@ -122,6 +122,24 @@ (Rational(fixnum_max) ** -bignum_value) }.should raise_error(ArgumentError) end + + it "raises an ArgumentError when self is < -1" do + -> { + (Rational(-2) ** bignum_value) + }.should raise_error(ArgumentError) + -> { + (Rational(fixnum_min) ** bignum_value) + }.should raise_error(ArgumentError) + end + + it "raises an ArgumentError when self is < -1 and the exponent is negative" do + -> { + (Rational(-2) ** -bignum_value) + }.should raise_error(ArgumentError) + -> { + (Rational(fixnum_min) ** -bignum_value) + }.should raise_error(ArgumentError) + end end # Fails on linux due to pow() bugs in glibc: http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866 @@ -148,26 +166,6 @@ }.should complain(/warning: in a\*\*b, b may be too big/) end end - - ruby_version_is "3.4" do - it "raises an ArgumentError when self < -1" do - -> { - (Rational(-2) ** bignum_value) - }.should raise_error(ArgumentError) - -> { - (Rational(fixnum_min) ** bignum_value) - }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when self is < -1 and the exponent is negative" do - -> { - (Rational(-2) ** -bignum_value) - }.should raise_error(ArgumentError) - -> { - (Rational(fixnum_min) ** -bignum_value) - }.should raise_error(ArgumentError) - end - end end end