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

ruby-changes:4274

From: ko1@a...
Date: Fri, 14 Mar 2008 01:43:02 +0900 (JST)
Subject: [ruby-changes:4274] matz - Ruby:r15764 (trunk): * numeric.c (fix_divmod): should return integer division.

matz	2008-03-14 01:37:54 +0900 (Fri, 14 Mar 2008)

  New Revision: 15764

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/version.h

  Log:
    * numeric.c (fix_divmod): should return integer division.  [ruby-dev:34006]

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/numeric.c?r1=15764&r2=15763&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=15764&r2=15763&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15764&r2=15763&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15763)
+++ ChangeLog	(revision 15764)
@@ -11,6 +11,10 @@
 
 	* trunk/string.c (hash): use inttypes.h instead of stdint.h.
 
+Thu Mar 13 10:42:46 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* numeric.c (fix_divmod): should return integer division.  [ruby-dev:34006]
+
 Thu Mar 13 03:12:48 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* lib/irb/cmd/help.rb: should be updated for new ri structure.
Index: numeric.c
===================================================================
--- numeric.c	(revision 15763)
+++ numeric.c	(revision 15764)
@@ -708,6 +708,22 @@
     return DOUBLE2NUM(mod);
 }
 
+static VALUE
+dbl2ival(double d)
+{
+    if (FIXABLE(d)) {
+	d = round(d);
+	return LONG2FIX((long)d);
+    }
+    else if (isnan(d) || isinf(d)) {
+	/* special case: cannot return integer value */
+	return rb_float_new(d);
+    }
+    else {
+	return rb_dbl2big(d);
+    }
+}
+
 /*
  *  call-seq:
  *     flt.divmod(numeric)    => array
@@ -735,16 +751,7 @@
 	return rb_num_coerce_bin(x, y, rb_intern("divmod"));
     }
     flodivmod(RFLOAT_VALUE(x), fy, &div, &mod);
-    if (FIXABLE(div)) {
-	val = round(div);
-	a = LONG2FIX(val);
-    }
-    else if (isnan(div) || isinf(div)) {
-	a = rb_float_new(div);
-    }
-    else {
-	a = rb_dbl2big(div);
-    }
+    a = dbl2ival(div);
     b = DOUBLE2NUM(mod);
     return rb_assoc_new(a, b);
 }
@@ -2319,7 +2326,7 @@
 	    volatile VALUE a, b;
 
 	    flodivmod((double)FIX2LONG(x), RFLOAT_VALUE(y), &div, &mod);
-	    a = DOUBLE2NUM(div);
+	    a = dbl2ival(div);
 	    b = DOUBLE2NUM(mod);
 	    return rb_assoc_new(a, b);
 	}
Index: version.h
===================================================================
--- version.h	(revision 15763)
+++ version.h	(revision 15764)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2008-03-13"
+#define RUBY_RELEASE_DATE "2008-03-14"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20080313
+#define RUBY_RELEASE_CODE 20080314
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 3
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 14
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

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

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