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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0