Project

General

Profile

Actions

Bug #3678

closed

CMath.sqrt(1.i) results to 0.0+0.0i

Added by phasis68 (Heesob Park) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3dev (2010-08-10 trunk 28955) [i386-mswin32_90]
Backport:
[ruby-core:31672]

Description

=begin
CMath.sqrt(1.i) should be equal to CMath.sqrt(1.0.i)

But CMath.sqrt(1.i) gives wrong result.

C:>ruby -rcmath -e "p CMath.sqrt(1.i)"
(0.0+0.0i)

C:>ruby -rcmath -e "p CMath.sqrt(1.0.i)"
(0.7071067811865476+0.7071067811865476i)

Here is the patch
--- cmath.rb 2010-08-11 11:30:07.087219552 +0900
+++ cmath.rb.new 2010-08-11 11:31:14.647214876 +0900
@@ -79,7 +79,7 @@
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
    =end
Actions #1

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

=begin
-devに振ります。

(2010/08/11 11:44), Heesob Park wrote:

Bug #3678: CMath.sqrt(1.i) results to 0.0+0.0i
http://redmine.ruby-lang.org/issues/show/3678

CMath.sqrt(1.i) should be equal to CMath.sqrt(1.0.i)

上記の主張についてどう思われますか?
この主張を採用するとしたらパッチ自体は問題ないように見えます。

=end

Actions #2

Updated by mrkn (Kenta Murata) over 13 years ago

=begin
むらたです。

On 2010/08/11, at 13:39, Urabe Shyouhei wrote:

-devに振ります。

(2010/08/11 11:44), Heesob Park wrote:

Bug #3678: CMath.sqrt(1.i) results to 0.0+0.0i
http://redmine.ruby-lang.org/issues/show/3678

CMath.sqrt(1.i) should be equal to CMath.sqrt(1.0.i)

上記の主張についてどう思われますか?
この主張を採用するとしたらパッチ自体は問題ないように見えます。

現在の CMath.sqrt の定義は実部も虚部も sqrt! の結果になっており、
結局 Float になるのですから分母を 2 から 2.0 に変更しても問題ないと思います。

--
Kenta Murata
OpenPGP FP = 1D69 ADDE 081C 9CC2 2E54 98C1 CEFE 8AFB 6081 B062

本を書きました!!
『Ruby 逆引きレシピ』 http://www.amazon.co.jp/dp/4798119881/mrkn-22

E-mail:
twitter: http://twitter.com/mrkn/
blog: http://d.hatena.ne.jp/mrkn/

=end

Actions #3

Updated by matz (Yukihiro Matsumoto) over 13 years ago

=begin
まつもと ゆきひろです

In message "Re: [ruby-dev:41996] Re: [ruby-core:31672] [Bug #3678] CMath.sqrt(1.i) results to 0.0+0.0i"
on Wed, 11 Aug 2010 13:48:04 +0900, Kenta Murata writes:

|現在の CMath.sqrt の定義は実部も虚部も sqrt! の結果になっており、
|結局 Float になるのですから分母を 2 から 2.0 に変更しても問題ないと思います。

コミットしてもらってもいいですか?

=end

Actions #4

Updated by mrkn (Kenta Murata) over 13 years ago

=begin
むらたです。

On 2010/08/11, at 18:01, Yukihiro Matsumoto wrote:

まつもと ゆきひろです

In message "Re: [ruby-dev:41996] Re: [ruby-core:31672] [Bug #3678] CMath.sqrt(1.i) results to 0.0+0.0i"
on Wed, 11 Aug 2010 13:48:04 +0900, Kenta Murata writes:

|現在の CMath.sqrt の定義は実部も虚部も sqrt! の結果になっており、
|結局 Float になるのですから分母を 2 から 2.0 に変更しても問題ないと思います。

コミットしてもらってもいいですか?

コミットしました。

そのついでに、test/test_cmath.rb がなかったので作りました。

--
Kenta Murata
OpenPGP FP = 1D69 ADDE 081C 9CC2 2E54 98C1 CEFE 8AFB 6081 B062

本を書きました!!
『Ruby 逆引きレシピ』 http://www.amazon.co.jp/dp/4798119881/mrkn-22

E-mail:
twitter: http://twitter.com/mrkn/
blog: http://d.hatena.ne.jp/mrkn/

=end

Actions #5

Updated by mrkn (Kenta Murata) over 13 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r28964.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions #6

Updated by phasis68 (Heesob Park) over 13 years ago

=begin
This bug still exists in ruby 1.9.2p0.

I think changeset r28964 should be backported.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0