Project

General

Profile

Actions

Bug #19335

closed

Integer#remainder and Numeric#remainder should respect #coerce

Added by kyanagi (Kouhei Yanagita) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21]
[ruby-core:111798]

Description

Thinking of the result of the following, Integer#remainder and Numeric#remainder should respect #coerce.
(BigDecimal#remainder seems to respect #coerce.)

c = Object.new
def c.coerce(other)
  [other, 10]
end

p 1234 / c          # => 123
p 1234.div(c)       # => 123
p 1234.quo(c)       # => (617/5)
p 1234.fdiv(c)      # => 123.4
p 1234 % c          # => 4
p 1234.modulo(c)    # => 4
p 1234.divmod(c)    # => [123, 4]
p 1234.remainder(c) # => in `remainder': comparison of Object with 0 failed (ArgumentError)

p 1234.0 / c          # => 123.4
p 1234.0.div(c)       # => 123
p 1234.0.quo(c)       # => 123.4
p 1234.0.fdiv(c)      # => 123.4
p 1234.0 % c          # => 4.0
p 1234.0.modulo(c)    # => 4.0
p 1234.0.divmod(c)    # => [123, 4.0]
p 1234.0.remainder(c) # => in `remainder': comparison of Object with 0 failed (ArgumentError)

require 'bigdecimal'
p BigDecimal('1234.0').remainder(c) # => 0.4e1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Assignee set to mrkn (Kenta Murata)

Sounds reasonable.

Actions #2

Updated by kyanagi (Kouhei Yanagita) over 1 year ago

  • Description updated (diff)
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|71ce7e1825c5b8fe08dd96cd77c6a379afd34256.


[Bug #19335] Integer#remainder should respect #coerce (#7120)

Also Numeric#remainder should.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0