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

ruby-changes:5429

From: shyouhei <ko1@a...>
Date: Sun, 8 Jun 2008 03:50:02 +0900 (JST)
Subject: [ruby-changes:5429] Ruby:r16931 (ruby_1_8_6): merge revision(s) 13902, 13907, 13914:

shyouhei	2008-06-08 03:46:09 +0900 (Sun, 08 Jun 2008)

  New Revision: 16931

  Modified files:
    branches/ruby_1_8_6/ChangeLog
    branches/ruby_1_8_6/configure.in
    branches/ruby_1_8_6/numeric.c
    branches/ruby_1_8_6/version.h

  Log:
    merge revision(s) 13902, 13907, 13914:
    * numeric.c (flo_divmod): round to the nearest integer.
      [ ruby-Bugs-14540 ]
    * numeric.c (flodivmod): work around for inifinity.
    * numeric.c (flo_divmod): work around for platforms have no round().
      [ruby-dev:32247]
    * numeric.c (round): fallback definition.
    * numeric.c (flo_divmod, flo_round): use round() always.
      [ruby-dev:32269]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/ChangeLog?r1=16931&r2=16930&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/version.h?r1=16931&r2=16930&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/configure.in?r1=16931&r2=16930&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_6/numeric.c?r1=16931&r2=16930&diff_format=u

Index: ruby_1_8_6/numeric.c
===================================================================
--- ruby_1_8_6/numeric.c	(revision 16930)
+++ ruby_1_8_6/numeric.c	(revision 16931)
@@ -63,6 +63,25 @@
 #define DBL_EPSILON 2.2204460492503131e-16
 #endif
 
+#ifndef HAVE_ROUND
+double
+round(x)
+    double x;
+{
+    double f;
+
+    if (x > 0.0) {
+	f = floor(x);
+	x = f + (x - f >= 0.5);
+    }
+    else if (x < 0.0) {
+	f = ceil(x);
+	x = f - (f - x >= 0.5);
+    }
+    return x;
+}
+#endif
+
 static ID id_coerce, id_to_i, id_eq;
 
 VALUE rb_cNumeric;
@@ -662,7 +681,10 @@
 	mod = x - z * y;
     }
 #endif
-    div = (x - mod) / y;
+    if (isinf(x) && !isinf(y) && !isnan(y))
+	div = x;
+    else
+	div = (x - mod) / y;
     if (y*mod < 0) {
 	mod += y;
 	div -= 1.0;
@@ -735,11 +757,14 @@
     }
     flodivmod(RFLOAT(x)->value, fy, &div, &mod);
     if (FIXABLE(div)) {
-        val = div;
-        a = LONG2FIX(val);
+        val = round(div);
+	a = LONG2FIX(val);
     }
+    else if (isnan(div) || isinf(div)) {
+	a = rb_float_new(div);
+    }
     else {
-        a = rb_dbl2big(div);
+	a = rb_dbl2big(div);
     }
     b = rb_float_new(mod);
     return rb_assoc_new(a, b);
@@ -1291,8 +1316,7 @@
     double f = RFLOAT(num)->value;
     long val;
 
-    if (f > 0.0) f = floor(f+0.5);
-    if (f < 0.0) f = ceil(f-0.5);
+    f = round(f);
 
     if (!FIXABLE(f)) {
 	return rb_dbl2big(f);
@@ -1530,7 +1554,7 @@
 	    char *s;
 
 	    sprintf(buf, "%-.10g", RFLOAT(val)->value);
-	    if (s = strchr(buf, ' ')) *s = '\0';
+	    if ((s = strchr(buf, ' ')) != 0) *s = '\0';
 	    rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
 	}
 
@@ -1681,7 +1705,7 @@
 	    char *s;
 
 	    sprintf(buf, "%-.10g", RFLOAT(val)->value);
-	    if (s = strchr(buf, ' ')) *s = '\0';
+	    if ((s = strchr(buf, ' ')) != 0) *s = '\0';
 	    rb_raise(rb_eRangeError, "float %s out of range of long long", buf);
 	}
 
Index: ruby_1_8_6/configure.in
===================================================================
--- ruby_1_8_6/configure.in	(revision 16930)
+++ ruby_1_8_6/configure.in	(revision 16931)
@@ -545,7 +545,7 @@
 	      getgroups setgroups getpriority getrlimit setrlimit sysconf\
 	      group_member dlopen sigprocmask\
 	      sigaction _setjmp setsid telldir seekdir fchmod mktime timegm\
-	      cosh sinh tanh setuid setgid setenv unsetenv)
+	      cosh sinh tanh round setuid setgid setenv unsetenv)
 AC_ARG_ENABLE(setreuid,
        [  --enable-setreuid       use setreuid()/setregid() according to need even if obsolete.],
        [use_setreuid=$enableval])
Index: ruby_1_8_6/ChangeLog
===================================================================
--- ruby_1_8_6/ChangeLog	(revision 16930)
+++ ruby_1_8_6/ChangeLog	(revision 16931)
@@ -1,3 +1,22 @@
+Sun Jun  8 03:42:10 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (round): fallback definition.
+
+	* numeric.c (flo_divmod, flo_round): use round() always.
+	  [ruby-dev:32269]
+
+Sun Jun  8 03:42:10 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (flodivmod): work around for inifinity.
+
+	* numeric.c (flo_divmod): work around for platforms have no round().
+	  [ruby-dev:32247]
+
+Sun Jun  8 03:42:10 2008  URABE Shyouhei  <shyouhei@i...>
+
+	* numeric.c (flo_divmod): round to the nearest integer.
+	  [ ruby-Bugs-14540 ]
+
 Sun Jun  8 03:28:53 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* lib/rexml/encodings/SHIFT-JIS.rb (REXML::Encoding): place -x for
Index: ruby_1_8_6/version.h
===================================================================
--- ruby_1_8_6/version.h	(revision 16930)
+++ ruby_1_8_6/version.h	(revision 16931)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2008-06-08"
 #define RUBY_VERSION_CODE 186
 #define RUBY_RELEASE_CODE 20080608
-#define RUBY_PATCHLEVEL 141
+#define RUBY_PATCHLEVEL 144
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8

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

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