ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120512] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass
@ 2025-01-06 23:20 MSP-Greg (Greg L) via ruby-core
  2025-01-07  2:50 ` [ruby-core:120513] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: MSP-Greg (Greg L) via ruby-core @ 2025-01-06 23:20 UTC (permalink / raw)
  To: ruby-core; +Cc: MSP-Greg (Greg L)

Issue #21008 has been reported by MSP-Greg (Greg L).

----------------------------------------
Bug #21008: Array#sum, Enumerator#sum, Numeric subclass
https://bugs.ruby-lang.org/issues/21008

* Author: MSP-Greg (Greg L)
* Status: Open
* ruby -v: ruby 3.5.0dev (2025-01-06T17:07:57Z master a61c16ba42) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
The following code seems to show a bug or 'quirk'.  When using a Numeric subclass, `Array#sum` works correctly, but `Enumerator#sum` does not.  They both work fine when using a `Float`.

```ruby
class Length < Numeric
  def initialize(val)
    @val = Float(val)
  end

  def to_f
    @val
  end
end

ary = []

#────────────────────────────────────────── Use Length

ary[0] = Length.new  5
ary[1] = Length.new 10
ary[2] = Length.new 20

puts "Length ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Length enum #{enum.sum}"  #=> 20.0

#────────────────────────────────────────── Use Float

ary[0] =  5.0
ary[1] = 10.0
ary[2] = 20.0

puts "Float  ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Float  enum #{enum.sum}"  #=> 35.0
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120513] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass
  2025-01-06 23:20 [ruby-core:120512] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass MSP-Greg (Greg L) via ruby-core
@ 2025-01-07  2:50 ` nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-11  7:17 ` [ruby-core:120610] " nagachika (Tomoyuki Chikanaga) via ruby-core
  2025-01-15  2:00 ` [ruby-core:120691] " k0kubun (Takashi Kokubun) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-01-07  2:50 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #21008 has been updated by nobu (Nobuyoshi Nakada).

Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED

https://github.com/ruby/ruby/pull/12522

----------------------------------------
Bug #21008: Array#sum, Enumerator#sum, Numeric subclass
https://bugs.ruby-lang.org/issues/21008#change-111305

* Author: MSP-Greg (Greg L)
* Status: Open
* ruby -v: ruby 3.5.0dev (2025-01-06T17:07:57Z master a61c16ba42) +PRISM [x86_64-linux]
* Backport: 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED
----------------------------------------
The following code seems to show a bug or 'quirk'.  When using a Numeric subclass, `Array#sum` works correctly, but `Enumerator#sum` does not.  They both work fine when using a `Float`.

```ruby
class Length < Numeric
  def initialize(val)
    @val = Float(val)
  end

  def to_f
    @val
  end
end

ary = []

#────────────────────────────────────────── Use Length

ary[0] = Length.new  5
ary[1] = Length.new 10
ary[2] = Length.new 20

puts "Length ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Length enum #{enum.sum}"  #=> 20.0

#────────────────────────────────────────── Use Float

ary[0] =  5.0
ary[1] = 10.0
ary[2] = 20.0

puts "Float  ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Float  enum #{enum.sum}"  #=> 35.0
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120610] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass
  2025-01-06 23:20 [ruby-core:120512] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass MSP-Greg (Greg L) via ruby-core
  2025-01-07  2:50 ` [ruby-core:120513] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-01-11  7:17 ` nagachika (Tomoyuki Chikanaga) via ruby-core
  2025-01-15  2:00 ` [ruby-core:120691] " k0kubun (Takashi Kokubun) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: nagachika (Tomoyuki Chikanaga) via ruby-core @ 2025-01-11  7:17 UTC (permalink / raw)
  To: ruby-core; +Cc: nagachika (Tomoyuki Chikanaga)

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

Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED, 3.4: REQUIRED

ruby_3_2 commit:845763fdf370846938b86a062827b237313c924f merged revision(s) commit:b176d4f52e4af67654814dab3e9c5f4bf9170e54.

----------------------------------------
Bug #21008: Array#sum, Enumerator#sum, Numeric subclass
https://bugs.ruby-lang.org/issues/21008#change-111441

* Author: MSP-Greg (Greg L)
* Status: Closed
* ruby -v: ruby 3.5.0dev (2025-01-06T17:07:57Z master a61c16ba42) +PRISM [x86_64-linux]
* Backport: 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED, 3.4: REQUIRED
----------------------------------------
The following code seems to show a bug or 'quirk'.  When using a Numeric subclass, `Array#sum` works correctly, but `Enumerator#sum` does not.  They both work fine when using a `Float`.

```ruby
class Length < Numeric
  def initialize(val)
    @val = Float(val)
  end

  def to_f
    @val
  end
end

ary = []

#────────────────────────────────────────── Use Length

ary[0] = Length.new  5
ary[1] = Length.new 10
ary[2] = Length.new 20

puts "Length ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Length enum #{enum.sum}"  #=> 20.0

#────────────────────────────────────────── Use Float

ary[0] =  5.0
ary[1] = 10.0
ary[2] = 20.0

puts "Float  ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Float  enum #{enum.sum}"  #=> 35.0
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120691] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass
  2025-01-06 23:20 [ruby-core:120512] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass MSP-Greg (Greg L) via ruby-core
  2025-01-07  2:50 ` [ruby-core:120513] " nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-11  7:17 ` [ruby-core:120610] " nagachika (Tomoyuki Chikanaga) via ruby-core
@ 2025-01-15  2:00 ` k0kubun (Takashi Kokubun) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2025-01-15  2:00 UTC (permalink / raw)
  To: ruby-core; +Cc: k0kubun (Takashi Kokubun)

Issue #21008 has been updated by k0kubun (Takashi Kokubun).

Backport changed from 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED, 3.4: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: DONE, 3.4: REQUIRED

ruby_3_3 commit:7b9caf19ba480d168ef4c5e93690735240975c91 merged revision(s) commit:b176d4f52e4af67654814dab3e9c5f4bf9170e54.

----------------------------------------
Bug #21008: Array#sum, Enumerator#sum, Numeric subclass
https://bugs.ruby-lang.org/issues/21008#change-111516

* Author: MSP-Greg (Greg L)
* Status: Closed
* ruby -v: ruby 3.5.0dev (2025-01-06T17:07:57Z master a61c16ba42) +PRISM [x86_64-linux]
* Backport: 3.1: REQUIRED, 3.2: DONE, 3.3: DONE, 3.4: REQUIRED
----------------------------------------
The following code seems to show a bug or 'quirk'.  When using a Numeric subclass, `Array#sum` works correctly, but `Enumerator#sum` does not.  They both work fine when using a `Float`.

```ruby
class Length < Numeric
  def initialize(val)
    @val = Float(val)
  end

  def to_f
    @val
  end
end

ary = []

#────────────────────────────────────────── Use Length

ary[0] = Length.new  5
ary[1] = Length.new 10
ary[2] = Length.new 20

puts "Length ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Length enum #{enum.sum}"  #=> 20.0

#────────────────────────────────────────── Use Float

ary[0] =  5.0
ary[1] = 10.0
ary[2] = 20.0

puts "Float  ary  #{ary.sum}"   #=> 35.0

enum = ary.each
puts "Float  enum #{enum.sum}"  #=> 35.0
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2025-01-15  2:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-06 23:20 [ruby-core:120512] [Ruby master Bug#21008] Array#sum, Enumerator#sum, Numeric subclass MSP-Greg (Greg L) via ruby-core
2025-01-07  2:50 ` [ruby-core:120513] " nobu (Nobuyoshi Nakada) via ruby-core
2025-01-11  7:17 ` [ruby-core:120610] " nagachika (Tomoyuki Chikanaga) via ruby-core
2025-01-15  2:00 ` [ruby-core:120691] " k0kubun (Takashi Kokubun) via ruby-core

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 NNTP newsgroup(s).