diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | lib/cmath.rb | 8 | ||||
-rw-r--r-- | test/test_cmath.rb | 4 |
3 files changed, 14 insertions, 6 deletions
@@ -1,3 +1,11 @@ +Mon Jun 13 14:35:00 2011 Kenta Murata <[email protected]> + + * lib/cmath.rb (CMath.cbrt): returns the principal value of the cube + root of the argument. fix #3676 + + * test/test_cmath.rb (test_cbrt_returns_principal_value_of_cube_root): + test for the above change. + Mon Jun 13 14:17:00 2011 Kenta Murata <[email protected]> * lib/test/unit.rb (Test::Unit::GlobOption#non_options): fix typo. diff --git a/lib/cmath.rb b/lib/cmath.rb index 24a0e70f9c..4751f6c4a1 100644 --- a/lib/cmath.rb +++ b/lib/cmath.rb @@ -122,13 +122,9 @@ module CMath end ## - # returns the cube root of +z+ + # returns the principal value of the cube root of +z+ def cbrt(z) - if z.real? - cbrt!(z) - else - Complex(z) ** (1.0/3) - end + Complex(z) ** (1.0/3) end ## diff --git a/test/test_cmath.rb b/test/test_cmath.rb index 46a357fab2..4f85ec3d04 100644 --- a/test/test_cmath.rb +++ b/test/test_cmath.rb @@ -5,4 +5,8 @@ class TestCMath < Test::Unit::TestCase def test_sqrt assert_equal CMath.sqrt(1.0.i), CMath.sqrt(1.i), '[ruby-core:31672]' end + + def test_cbrt_returns_principal_value_of_cube_root + assert_equal CMath.cbrt(-8), (-8)**(1.0/3), '#3676' + end end |