summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-complex/test/complex.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-08-09 21:47:00 +0900
committerGitHub <[email protected]>2019-08-09 21:47:00 +0900
commit496a2c3264aa3a2dbc50bb01e545ed4803718213 (patch)
treece1ecd89ddb7d67171dfda216e6e82ac79c0b373 /mrbgems/mruby-complex/test/complex.rb
parent438638b42e13297d38198b15f2fc007e0f5a44a8 (diff)
parent1cd0ff0d42ea4fb385288d3bd2c440a1f46e08af (diff)
downloadmruby-496a2c3264aa3a2dbc50bb01e545ed4803718213.tar.gz
mruby-496a2c3264aa3a2dbc50bb01e545ed4803718213.zip
Merge pull request #4623 from chasonr/complex-fixes
Avoid premature overflow in Complex#abs and Complex#/
Diffstat (limited to 'mrbgems/mruby-complex/test/complex.rb')
-rw-r--r--mrbgems/mruby-complex/test/complex.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/mrbgems/mruby-complex/test/complex.rb b/mrbgems/mruby-complex/test/complex.rb
index 4ae80515b..d996e8277 100644
--- a/mrbgems/mruby-complex/test/complex.rb
+++ b/mrbgems/mruby-complex/test/complex.rb
@@ -59,6 +59,15 @@ assert 'Complex#/' do
assert_complex Complex(-2, 9) / Complex(-9, 2), ((36 / 85) - (77i / 85))
assert_complex Complex(9, 8) / 4 , ((9 / 4) + 2i)
assert_complex Complex(20, 9) / 9.8 , (2.0408163265306123 + 0.9183673469387754i)
+ if 1e39.infinite? then
+ # MRB_USE_FLOAT in effect
+ ten = 1e21
+ one = 1e20
+ else
+ ten = 1e201
+ one = 1e200
+ end
+ assert_complex Complex(ten, ten) / Complex(one, one), Complex(10.0, 0.0)
end
assert 'Complex#==' do
@@ -70,6 +79,14 @@ end
assert 'Complex#abs' do
assert_float Complex(-1).abs, 1
assert_float Complex(3.0, -4.0).abs, 5.0
+ if 1e39.infinite? then
+ # MRB_USE_FLOAT in effect
+ exp = 125
+ else
+ exp = 1021
+ end
+ assert_true Complex(3.0*2.0**exp, 4.0*2.0**exp).abs.finite?
+ assert_float Complex(3.0*2.0**exp, 4.0*2.0**exp).abs, 5.0*2.0**exp
end
assert 'Complex#abs2' do