aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-01 22:48:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-01 22:48:01 +0000
commit38e631421b157237c9e58df08451d700f0fea351 (patch)
tree9a030f48a29b7193937b15baa2d251aa58469620 /rational.c
parent7e1d99cf55e48fddc761984a4a41a54047fce6e0 (diff)
downloadruby-38e631421b157237c9e58df08451d700f0fea351.tar.gz
rational.c: improves Rational#round rdoc [ci skip]
* rational.c (nurat_round_n): [DOC] improves Integer#round documentation as well as Float#round. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/rational.c b/rational.c
index cb555426ec..9601ee76df 100644
--- a/rational.c
+++ b/rational.c
@@ -1510,11 +1510,12 @@ nurat_truncate_n(int argc, VALUE *argv, VALUE self)
/*
* 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, VALUE self)
*
* 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)