ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109879] [Ruby master Bug#19004] Complex can be nested by Complex.polar
@ 2022-09-10 17:46 msnm (Masahiro Nomoto)
  2022-10-16 19:55 ` [ruby-core:110322] " stevegeek (Stephen Ierodiaconou)
  2022-11-05  5:25 ` [ruby-core:110614] " nagachika (Tomoyuki Chikanaga)
  0 siblings, 2 replies; 3+ messages in thread
From: msnm (Masahiro Nomoto) @ 2022-09-10 17:46 UTC (permalink / raw)
  To: ruby-core

Issue #19004 has been reported by msnm (Masahiro Nomoto).

----------------------------------------
Bug #19004: Complex can be nested by Complex.polar
https://bugs.ruby-lang.org/issues/19004

* 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110322] [Ruby master Bug#19004] Complex can be nested by Complex.polar
  2022-09-10 17:46 [ruby-core:109879] [Ruby master Bug#19004] Complex can be nested by Complex.polar msnm (Masahiro Nomoto)
@ 2022-10-16 19:55 ` stevegeek (Stephen Ierodiaconou)
  2022-11-05  5:25 ` [ruby-core:110614] " nagachika (Tomoyuki Chikanaga)
  1 sibling, 0 replies; 3+ messages in thread
From: stevegeek (Stephen Ierodiaconou) @ 2022-10-16 19:55 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110614] [Ruby master Bug#19004] Complex can be nested by Complex.polar
  2022-09-10 17:46 [ruby-core:109879] [Ruby master Bug#19004] Complex can be nested by Complex.polar msnm (Masahiro Nomoto)
  2022-10-16 19:55 ` [ruby-core:110322] " stevegeek (Stephen Ierodiaconou)
@ 2022-11-05  5:25 ` nagachika (Tomoyuki Chikanaga)
  1 sibling, 0 replies; 3+ messages in thread
From: nagachika (Tomoyuki Chikanaga) @ 2022-11-05  5:25 UTC (permalink / raw)
  To: ruby-core

Issue #19004 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE

ruby_3_1 597ce7966c38e4f7fc7368a860ac2d056de794ba merged revision(s) 54cad3123a07583c90e85bcfc55ebd87124c1250.

----------------------------------------
Bug #19004: Complex can be nested by Complex.polar
https://bugs.ruby-lang.org/issues/19004#change-99946

* Author: msnm (Masahiro Nomoto)
* Status: Closed
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
----------------------------------------
`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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-05  5:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-10 17:46 [ruby-core:109879] [Ruby master Bug#19004] Complex can be nested by Complex.polar msnm (Masahiro Nomoto)
2022-10-16 19:55 ` [ruby-core:110322] " stevegeek (Stephen Ierodiaconou)
2022-11-05  5:25 ` [ruby-core:110614] " nagachika (Tomoyuki Chikanaga)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).