From: "stevegeek (Stephen Ierodiaconou)" Date: 2022-10-16T19:55:43+00:00 Subject: [ruby-core:110322] [Ruby master Bug#19004] Complex can be nested by Complex.polar Issue #19004 has been updated by stevegeek (Stephen Ierodiaconou). I thought to try fixing this issue as a first contribution to Ruby. I have a proposed fix here https://github.com/ruby/ruby/pull/6568 Details are on the PR, but in summary, I believe that the ability to pass a Complex as the abs argument is the expected behaviour (given other methods on Complex also accept Complex value as long as they are real, in the sense they have a zero imaginary part). However Complex.polar with a single argument creates the new Complex without first extracting the real part of the argument, so `Complex.polar(1+0.0i).real` => (1+0i) The propose fix simply ensures that the single argument case is handled in the same way as the 2 argument case, so `Complex.polar(1+0.0i).real` => 1 ---------------------------------------- Bug #19004: Complex can be nested by Complex.polar https://bugs.ruby-lang.org/issues/19004#change-99616 * Author: msnm (Masahiro Nomoto) * Status: Open * Priority: Normal * ruby -v: 3.1.2 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `Complex.polar` with one argument can return a "nested" Complex instance, whose real part is also a Complex one. ```ruby puts RUBY_DESCRIPTION # ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux] p Complex.polar(1+0i) # ((1+0i)+0i) p 5.times.inject(1) { |num, _| Complex.polar(num) } # (((((1+0i)+0i)+0i)+0i)+0i) ``` In Ruby < 2.7 , it simply raises an error when the argument is an instance of Complex (i.e. `obj.real? == false`). ```ruby puts RUBY_DESCRIPTION # ruby 2.6.10p210 (2022-04-12 revision 67958) [x86_64-linux] p Complex.polar(1+0i) # TypeError (not a real) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: