mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
da923d2b1f
commit
e6bea8978c
3 changed files with 14 additions and 6 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Mon Jun 13 14:35:00 2011 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
|
* 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@mrkn.jp>
|
Mon Jun 13 14:17:00 2011 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
* lib/test/unit.rb (Test::Unit::GlobOption#non_options): fix typo.
|
* lib/test/unit.rb (Test::Unit::GlobOption#non_options): fix typo.
|
||||||
|
|
|
@ -122,13 +122,9 @@ module CMath
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# returns the cube root of +z+
|
# returns the principal value of the cube root of +z+
|
||||||
def cbrt(z)
|
def cbrt(z)
|
||||||
if z.real?
|
Complex(z) ** (1.0/3)
|
||||||
cbrt!(z)
|
|
||||||
else
|
|
||||||
Complex(z) ** (1.0/3)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -5,4 +5,8 @@ class TestCMath < Test::Unit::TestCase
|
||||||
def test_sqrt
|
def test_sqrt
|
||||||
assert_equal CMath.sqrt(1.0.i), CMath.sqrt(1.i), '[ruby-core:31672]'
|
assert_equal CMath.sqrt(1.0.i), CMath.sqrt(1.i), '[ruby-core:31672]'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cbrt_returns_principal_value_of_cube_root
|
||||||
|
assert_equal CMath.cbrt(-8), (-8)**(1.0/3), '#3676'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue