Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced RDoc for Numeric#% #4954

Merged
merged 2 commits into from Oct 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions numeric.c
Expand Up @@ -620,13 +620,38 @@ num_div(VALUE x, VALUE y)

/*
* 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
Expand Down Expand Up @@ -3716,7 +3741,6 @@ rb_int_idiv(VALUE x, VALUE y)
*
* See Numeric#divmod for more information.
*/

static VALUE
fix_mod(VALUE x, VALUE y)
{
Expand Down