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

ruby-changes:15955

From: naruse <ko1@a...>
Date: Wed, 19 May 2010 21:19:51 +0900 (JST)
Subject: [ruby-changes:15955] Ruby:r27898 (ruby_1_9_2): merge revision(s) 27890:

naruse	2010-05-19 21:19:46 +0900 (Wed, 19 May 2010)

  New Revision: 27898

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

  Log:
    merge revision(s) 27890:
    * numeric.c (rb_num2ulong): use rb_big2ulong for data from
      Bignum. Without this 32bit integer on 32bit environment
      can't converted into long.
      This fixes 1) and 2) of [ruby-dev:41289]

  Modified files:
    branches/ruby_1_9_2/numeric.c

Index: ruby_1_9_2/numeric.c
===================================================================
--- ruby_1_9_2/numeric.c	(revision 27897)
+++ ruby_1_9_2/numeric.c	(revision 27898)
@@ -1720,10 +1720,35 @@
 VALUE
 rb_num2ulong(VALUE val)
 {
-    if (TYPE(val) == T_BIGNUM) {
+  again:
+    if (NIL_P(val)) {
+       rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
+    }
+
+    if (FIXNUM_P(val)) return FIX2LONG(val); /* this is FIX2LONG, inteneded */
+
+    switch (TYPE(val)) {
+      case T_FLOAT:
+       if (RFLOAT_VALUE(val) <= (double)LONG_MAX
+           && RFLOAT_VALUE(val) >= (double)LONG_MIN) {
+           return (RFLOAT_VALUE(val));
+       }
+       else {
+           char buf[24];
+           char *s;
+
+           snprintf(buf, sizeof(buf), "%-.10g", RFLOAT_VALUE(val));
+           if ((s = strchr(buf, ' ')) != 0) *s = '\0';
+           rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
+       }
+
+      case T_BIGNUM:
 	return rb_big2ulong(val);
+
+      default:
+       val = rb_to_int(val);
+       goto again;
     }
-    return (VALUE)rb_num2long(val);
 }
 
 #if SIZEOF_INT < SIZEOF_VALUE

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

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