diff options
author | Yusuke Endoh <[email protected]> | 2024-11-08 14:46:35 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2024-11-08 19:48:56 +0900 |
commit | 45cd4a8296814f3b082dfb906cdef29974726731 (patch) | |
tree | f0bb06b401fd95c09e9b44281473fafe5621c67b /test/ruby/test_integer.rb | |
parent | f7b334e002eba25e386917337771b65bed5297f8 (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 'test/ruby/test_integer.rb')
-rw-r--r-- | test/ruby/test_integer.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index c2cad36aa4..7819e03e28 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -57,20 +57,19 @@ class TestInteger < Test::Unit::TestCase nil end, "[ruby-dev:32084] [ruby-dev:34547]") - x = EnvUtil.suppress_warning {2 ** -0x4000000000000000} - assert_in_delta(0.0, (x / 2), Float::EPSILON) + assert_raise(ArgumentError) {2 ** -0x4000000000000000} <<~EXPRS.each_line.with_index(__LINE__+1) do |expr, line| crash01: 111r+11**-11111161111111 crash02: 1118111111111**-1111111111111111**1+1==11111 - crash03: -1111111**-1111*11 - -1111111** -111111111 + crash03: -1111111**-1111*11 - -11** -11111111 crash04: 1118111111111** -1111111111111111**1+11111111111**1 ===111 crash05: 11** -111155555555555555 -55 !=5-555 crash07: 1 + 111111111**-1111811111 crash08: 18111111111**-1111111111111111**1 + 1111111111**-1111**1 crash10: -7 - -1111111** -1111**11 crash12: 1118111111111** -1111111111111111**1 + 1111 - -1111111** -1111*111111111119 - crash13: 1.0i - -1111111** -111111111 + crash13: 1.0i - -11** -11111111 crash14: 11111**111111111**111111 * -11111111111111111111**-111111111111 crash15: ~1**1111 + -~1**~1**111 crash17: 11** -1111111**1111 /11i @@ -80,7 +79,7 @@ class TestInteger < Test::Unit::TestCase crash21: 11**-10111111119-1i -1r EXPRS name, expr = expr.split(':', 2) - assert_ruby_status(%w"-W0", expr, name) + assert_ruby_status(%w"-W0", "begin; #{ expr }; rescue ArgumentError; end", name) end end |