[前][次][番号順一覧][スレッド一覧]

ruby-changes:68412

From: Burdette <ko1@a...>
Date: Tue, 12 Oct 2021 22:06:20 +0900 (JST)
Subject: [ruby-changes:68412] bb66729b5f (master): Enhanced RDoc for Numeric#% (#4954)

https://git.ruby-lang.org/ruby.git/commit/?id=bb66729b5f

From bb66729b5ffb0e59825503d5d5b703d60c8a3f85 Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Tue, 12 Oct 2021 08:06:05 -0500
Subject: Enhanced RDoc for Numeric#% (#4954)

---
 numeric.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/numeric.c b/numeric.c
index 4a4a128bb5..e0c253e736 100644
--- a/numeric.c
+++ b/numeric.c
@@ -620,13 +620,38 @@ num_div(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L620
 
 /*
  *  call-seq:
- *     num.modulo(numeric)  ->  real
+ *    self % other -> real_numeric
  *
- *  <code>x.modulo(y)</code> means <code>x-y*(x/y).floor</code>.
+ *  Returns +self+ modulo +other+ as a real number.
  *
- *  Equivalent to <code>num.divmod(numeric)[1]</code>.
+ *  Of the Core and Standard Library classes,
+ *  only Rational uses this implementation.
+ *
+ *  For \Rational +r+ and real number +n+, these expressions are equivalent:
+ *
+ *    c % n
+ *    c-n*(c/n).floor
+ *    c.divmod(n)[1]
  *
  *  See Numeric#divmod.
+ *
+ *  Examples:
+ *
+ *    r = Rational(1, 2)    # => (1/2)
+ *    r2 = Rational(2, 3)   # => (2/3)
+ *    r % r2                # => (1/2)
+ *    r % 2                 # => (1/2)
+ *    r % 2.0               # => 0.5
+ *
+ *    r = Rational(301,100) # => (301/100)
+ *    r2 = Rational(7,5)    # => (7/5)
+ *    r % r2                # => (21/100)
+ *    r % -r2               # => (-119/100)
+ *    (-r) % r2             # => (119/100)
+ *    (-r) %-r2             # => (-21/100)
+ *
+ *  Numeric#modulo is an alias for Numeric#%.
+ *
  */
 
 static VALUE
@@ -3718,7 +3743,6 @@ rb_int_idiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3743
  *
  *  See Numeric#divmod for more information.
  */
-
 static VALUE
 fix_mod(VALUE x, VALUE y)
 {
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]