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

ruby-changes:21013

From: marcandre <ko1@a...>
Date: Thu, 25 Aug 2011 08:05:34 +0900 (JST)
Subject: [ruby-changes:21013] marcandRe: r33062 (ruby_1_9_3): * backport r33060, 33061 from trunk

marcandre	2011-08-25 08:04:50 +0900 (Thu, 25 Aug 2011)

  New Revision: 33062

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33062

  Log:
    * backport r33060, 33061 from trunk
    
    * numeric.c (int_round): Fix Integer#round [ruby-core:39096]

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/numeric.c

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 33061)
+++ ruby_1_9_3/ChangeLog	(revision 33062)
@@ -1,3 +1,7 @@
+Thu Aug 25 08:04:08 2011  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* numeric.c (int_round): Fix Integer#round [ruby-core:39096]
+
 Thu Aug 25 06:51:08 2011  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych.rb: Fixing psych version number.
Index: ruby_1_9_3/numeric.c
===================================================================
--- ruby_1_9_3/numeric.c	(revision 33061)
+++ ruby_1_9_3/numeric.c	(revision 33062)
@@ -1602,7 +1602,7 @@
  *     num.round([ndigits])  ->  integer or float
  *
  *  Rounds <i>num</i> to a given precision in decimal digits (default 0 digits).
- *  Precision may be negative.  Returns a floating point number when ndigits
+ *  Precision may be negative.  Returns a floating point number when <i>ndigits</i>
  *  is more than zero.  <code>Numeric</code> implements this by converting itself
  *  to a <code>Float</code> and invoking <code>Float#round</code>.
  */
@@ -2031,7 +2031,6 @@
  *     int.to_int    ->  integer
  *     int.floor     ->  integer
  *     int.ceil      ->  integer
- *     int.round     ->  integer
  *     int.truncate  ->  integer
  *
  *  As <i>int</i> is already an <code>Integer</code>, all these
@@ -3283,7 +3282,7 @@
 
 /*
  *  call-seq:
- *     num.round([ndigits])  ->  integer or float
+ *     int.round([ndigits])  ->  integer or float
  *
  *  Rounds <i>flt</i> to a given precision in decimal digits (default 0 digits).
  *  Precision may be negative.  Returns a floating point number when +ndigits+
@@ -3299,6 +3298,7 @@
 {
     VALUE n, f, h, r;
     int ndigits;
+    ID op;
 
     if (argc == 0) return num;
     rb_scan_args(argc, argv, "1", &n);
@@ -3325,7 +3325,8 @@
     h = rb_funcall(f, '/', 1, INT2FIX(2));
     r = rb_funcall(num, '%', 1, f);
     n = rb_funcall(num, '-', 1, r);
-    if (!RTEST(rb_funcall(r, '<', 1, h))) {
+    op = RTEST(rb_funcall(num, '<', 1, INT2FIX(0))) ? rb_intern("<=") : '<';
+    if (!RTEST(rb_funcall(r, op, 1, h))) {
 	n = rb_funcall(n, '+', 1, f);
     }
     return n;

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

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