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

ruby-changes:68486

From: Burdette <ko1@a...>
Date: Sat, 16 Oct 2021 01:58:12 +0900 (JST)
Subject: [ruby-changes:68486] 2043c2e7e4 (master): Enhanced RDoc for numeric.c (#4964)

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

From 2043c2e7e493ce44e66e62968c7ace237c137cb5 Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Fri, 15 Oct 2021 11:57:49 -0500
Subject: Enhanced RDoc for numeric.c (#4964)

Treats Integer#% and Float#%.
---
 numeric.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 55 insertions(+), 16 deletions(-)

diff --git a/numeric.c b/numeric.c
index e0c253e736..f6de533e1b 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1195,13 +1195,33 @@ ruby_float_mod(double x, double y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1195
 
 /*
  *  call-seq:
- *     float % other        ->  float
- *     float.modulo(other)  ->  float
+ *    self % other -> float
  *
- *  Returns the modulo after division of +float+ by +other+.
+ *  Returns +self+ modulo +other+ as a float.
+ *
+ *  For float +f+ and real number +r+, these expressions are equivalent:
+ *
+ *    f % r
+ *    f-r*(f/r).floor
+ *    f.divmod(r)[1]
+ *
+ *  See Numeric#divmod.
+ *
+ *  Examples:
+ *
+ *    10.0 % 2              # => 0.0
+ *    10.0 % 3              # => 1.0
+ *    10.0 % 4              # => 2.0
+ *
+ *    10.0 % -2             # => 0.0
+ *    10.0 % -3             # => -2.0
+ *    10.0 % -4             # => -2.0
+ *
+ *    10.0 % 4.0            # => 2.0
+ *    10.0 % Rational(4, 1) # => 2.0
+ *
+ *  Float#modulo is an alias for Float#%.
  *
- *     6543.21.modulo(137)      #=> 104.21000000000004
- *     6543.21.modulo(137.24)   #=> 92.92999999999961
  */
 
 static VALUE
@@ -3732,17 +3752,6 @@ rb_int_idiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3752
     return num_div(x, y);
 }
 
-/*
- *  Document-method: Integer#%
- *  Document-method: Integer#modulo
- *  call-seq:
- *     int % other        ->  real
- *     int.modulo(other)  ->  real
- *
- *  Returns +int+ modulo +other+.
- *
- *  See Numeric#divmod for more information.
- */
 static VALUE
 fix_mod(VALUE x, VALUE y)
 {
@@ -3762,6 +3771,36 @@ fix_mod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3771
     }
 }
 
+/*
+ *  call-seq:
+ *    self % other -> real_number
+ *
+ *  Returns +self+ modulo +other+ as a real number.
+ *
+ *  For integer +n+ and real number +r+, these expressions are equivalent:
+ *
+ *    n % r
+ *    n-r*(n/r).floor
+ *    n.divmod(r)[1]
+ *
+ *  See Numeric#divmod.
+ *
+ *  Examples:
+ *
+ *    10 % 2              # => 0
+ *    10 % 3              # => 1
+ *    10 % 4              # => 2
+ *
+ *    10 % -2             # => 0
+ *    10 % -3             # => -2
+ *    10 % -4             # => -2
+ *
+ *    10 % 3.0            # => 1.0
+ *    10 % Rational(3, 1) # => (1/1)
+ *
+ *  Integer#modulo is an alias for Integer#%.
+ *
+ */
 VALUE
 rb_int_modulo(VALUE x, VALUE y)
 {
-- 
cgit v1.2.1


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

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