[前][次][番号順一覧][スレッド一覧]

ruby-changes:20000

From: mrkn <ko1@a...>
Date: Mon, 13 Jun 2011 14:37:11 +0900 (JST)
Subject: [ruby-changes:20000] mrkn:r32047 (trunk): * lib/cmath.rb (CMath.cbrt): returns the principal value of the cube

mrkn	2011-06-13 14:36:59 +0900 (Mon, 13 Jun 2011)

  New Revision: 32047

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32047

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/cmath.rb
    trunk/test/test_cmath.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32046)
+++ ChangeLog	(revision 32047)
@@ -1,3 +1,11 @@
+Mon Jun 13 14:35:00 2011  Kenta Murata  <mrkn@m...>
+
+	* 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  <mrkn@m...>
 
 	* lib/test/unit.rb (Test::Unit::GlobOption#non_options): fix typo.
Index: lib/cmath.rb
===================================================================
--- lib/cmath.rb	(revision 32046)
+++ lib/cmath.rb	(revision 32047)
@@ -122,13 +122,9 @@
   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
 
   ##
Index: test/test_cmath.rb
===================================================================
--- test/test_cmath.rb	(revision 32046)
+++ test/test_cmath.rb	(revision 32047)
@@ -5,4 +5,8 @@
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]