From 9b0b9ac237c60d34c9cd06538d1a133eed9f7130 Mon Sep 17 00:00:00 2001 From: mrkn Date: Wed, 11 Aug 2010 14:30:47 +0000 Subject: [PATCH] * lib/cmath.rb (CMath.sqrt): use floating-point value. [ruby-core:31672] [Bug #3678] * test/test_cmath.rb: added for testing lib/cmath.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/cmath.rb | 2 +- test/test_cmath.rb | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/test_cmath.rb diff --git a/ChangeLog b/ChangeLog index a4d5ea1cdc..2465e5d387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Aug 11 23:28:22 2010 Kenta Murata + + * lib/cmath.rb (CMath.sqrt): use floating-point value. + [ruby-core:31672] [Bug #3678] + + * test/test_cmath.rb: added for testing lib/cmath.rb. + Wed Aug 11 20:57:25 2010 Kazuhiro NISHIYAMA * NEWS: merge from branches/ruby_1_9_2, and move io/console. diff --git a/lib/cmath.rb b/lib/cmath.rb index 976f269299..3c94221f2c 100644 --- a/lib/cmath.rb +++ b/lib/cmath.rb @@ -79,7 +79,7 @@ module CMath else r = z.abs x = z.real - Complex(sqrt!((r + x) / 2), sqrt!((r - x) / 2)) + Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0)) end end end diff --git a/test/test_cmath.rb b/test/test_cmath.rb new file mode 100644 index 0000000000..46a357fab2 --- /dev/null +++ b/test/test_cmath.rb @@ -0,0 +1,8 @@ +require 'test/unit' +require 'cmath' + +class TestCMath < Test::Unit::TestCase + def test_sqrt + assert_equal CMath.sqrt(1.0.i), CMath.sqrt(1.i), '[ruby-core:31672]' + end +end