From: "nobu (Nobuyoshi Nakada) via ruby-core" Date: 2023-01-13T15:06:33+00:00 Subject: [ruby-core:111803] [Ruby master Bug#19335] Integer#remainder and Numeric#remainder should respect #coerce Issue #19335 has been updated by nobu (Nobuyoshi Nakada). https://github.com/ruby/ruby/pull/7120 ---------------------------------------- Bug #19335: Integer#remainder and Numeric#remainder should respect #coerce https://bugs.ruby-lang.org/issues/19335#change-101214 * Author: kyanagi (Kouhei Yanagita) * Status: Open * Priority: Normal * Assignee: mrkn (Kenta Murata) * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Thinking of the result of the following, `Integer#remainder` and `Numeric#remainder` should respect `#coerce`. (`BigDecimal#remainder` seems to respect `#coerce`.) ```Ruby 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 ``` -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/