ruby-changes:46121
From: nobu <ko1@a...>
Date: Sun, 2 Apr 2017 07:48:04 +0900 (JST)
Subject: [ruby-changes:46121] nobu:r58235 (trunk): rational.c: improves Rational#round rdoc [ci skip]
nobu 2017-04-02 07:48:01 +0900 (Sun, 02 Apr 2017) New Revision: 58235 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58235 Log: rational.c: improves Rational#round rdoc [ci skip] * rational.c (nurat_round_n): [DOC] improves Integer#round documentation as well as Float#round. Modified files: trunk/rational.c Index: rational.c =================================================================== --- rational.c (revision 58234) +++ rational.c (revision 58235) @@ -1510,11 +1510,12 @@ nurat_truncate_n(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/rational.c#L1510 /* * call-seq: - * rat.round -> integer - * rat.round(precision=0) -> integer or rational + * rat.round([ndigits] [, half: symbol]) -> integer or rational * - * Returns the truncated value (toward the nearest integer; - * 0.5 => 1; -0.5 => -1). + * Rounds +rat+ to a given precision in decimal digits (default 0 digits). + * + * Precision may be negative. Returns a rational when +ndigits+ + * is more than zero. * * Rational(3).round #=> 3 * Rational(2, 3).round #=> 1 @@ -1526,6 +1527,15 @@ nurat_truncate_n(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/rational.c#L1527 * * Rational('-123.456').round(+1).to_f #=> -123.5 * Rational('-123.456').round(-1) #=> -120 + * + * The <code>half:</code> optional keyword same as Float#round is available. + * + * Rational(25, 100).round(1, half: :up) #=> (3/10) + * Rational(25, 100).round(1, half: :even) #=> (1/5) + * Rational(25, 100).round(1, half: :down) #=> (1/5) + * Rational(35, 100).round(1, half: :up) #=> (2/5) + * Rational(35, 100).round(1, half: :even) #=> (2/5) + * Rational(35, 100).round(1, half: :down) #=> (3/10) */ static VALUE nurat_round_n(int argc, VALUE *argv, VALUE self) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/