summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-complex/test
diff options
context:
space:
mode:
authorRay Chason <[email protected]>2019-08-09 00:08:36 -0400
committerRay Chason <[email protected]>2019-08-09 00:08:36 -0400
commit1cd0ff0d42ea4fb385288d3bd2c440a1f46e08af (patch)
treece1ecd89ddb7d67171dfda216e6e82ac79c0b373 /mrbgems/mruby-complex/test
parentc181d1e7fa80b1cc0551f8fbd85ab6f7419b7887 (diff)
downloadmruby-1cd0ff0d42ea4fb385288d3bd2c440a1f46e08af.tar.gz
mruby-1cd0ff0d42ea4fb385288d3bd2c440a1f46e08af.zip
Avoid overflow and underflow in Complex#/
Diffstat (limited to 'mrbgems/mruby-complex/test')
-rw-r--r--mrbgems/mruby-complex/test/complex.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/mrbgems/mruby-complex/test/complex.rb b/mrbgems/mruby-complex/test/complex.rb
index dcc0f3bef..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
@@ -76,8 +85,8 @@ assert 'Complex#abs' do
else
exp = 1021
end
- assert_true Complex(3.0*2**exp, 4.0*2**exp).abs.finite?
- assert_float Complex(3.0*2**exp, 4.0*2**exp).abs, 5.0*2**exp
+ 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