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

ruby-changes:30793

From: nobu <ko1@a...>
Date: Sun, 8 Sep 2013 04:04:26 +0900 (JST)
Subject: [ruby-changes:30793] nobu:r42872 (trunk): bignum.c: split rb_big_fdiv and big_fdiv

nobu	2013-09-08 04:04:15 +0900 (Sun, 08 Sep 2013)

  New Revision: 42872

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

  Log:
    bignum.c: split rb_big_fdiv and big_fdiv
    
    * bignum.c (rb_big_fdiv): split with big_fdiv by divider type.

  Modified files:
    trunk/bignum.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 42871)
+++ bignum.c	(revision 42872)
@@ -6291,12 +6291,11 @@ big_shift(VALUE x, long n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6291
 }
 
 static VALUE
-big_fdiv(VALUE x, VALUE y)
+big_fdiv(VALUE x, VALUE y, long ey)
 {
 #define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
     VALUE z;
-    long l, ex, ey;
-    int i;
+    long l, ex;
 
     bigtrunc(x);
     l = RBIGNUM_LEN(x);
@@ -6304,23 +6303,6 @@ big_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6303
     ex -= 2 * DBL_BIGDIG * BITSPERDIG;
     if (ex) x = big_shift(x, ex);
 
-    switch (TYPE(y)) {
-      case T_FIXNUM:
-	y = rb_int2big(FIX2LONG(y));
-      case T_BIGNUM:
-	bigtrunc(y);
-	l = RBIGNUM_LEN(y);
-	ey = l * BITSPERDIG - nlz(BDIGITS(y)[l-1]);
-	ey -= DBL_BIGDIG * BITSPERDIG;
-	if (ey) y = big_shift(y, ey);
-	break;
-      case T_FLOAT:
-	y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG));
-	ey = i - DBL_MANT_DIG;
-	break;
-      default:
-	rb_bug("big_fdiv");
-    }
     bigdivrem(x, y, &z, 0);
     l = ex - ey;
 #if SIZEOF_LONG > SIZEOF_INT
@@ -6333,6 +6315,26 @@ big_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6315
     return DBL2NUM(ldexp(big2dbl(z), (int)l));
 }
 
+static VALUE
+big_fdiv_int(VALUE x, VALUE y)
+{
+    long l, ey;
+    bigtrunc(y);
+    l = RBIGNUM_LEN(y);
+    ey = l * BITSPERDIG - nlz(BDIGITS(y)[l-1]);
+    ey -= DBL_BIGDIG * BITSPERDIG;
+    if (ey) y = big_shift(y, ey);
+    return big_fdiv(x, y, ey);
+}
+
+static VALUE
+big_fdiv_float(VALUE x, VALUE y)
+{
+    int i;
+    y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG));
+    return big_fdiv(x, y, i - DBL_MANT_DIG);
+}
+
 /*
  *  call-seq:
   *     big.fdiv(numeric) -> float
@@ -6356,13 +6358,13 @@ rb_big_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6358
       case T_FIXNUM:
 	dy = (double)FIX2LONG(y);
 	if (isinf(dx))
-	    return big_fdiv(x, y);
+	    return big_fdiv_int(x, rb_int2big(FIX2LONG(y)));
 	break;
 
       case T_BIGNUM:
 	dy = rb_big2dbl(y);
 	if (isinf(dx) || isinf(dy))
-	    return big_fdiv(x, y);
+	    return big_fdiv_int(x, y);
 	break;
 
       case T_FLOAT:
@@ -6370,7 +6372,7 @@ rb_big_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6372
 	if (isnan(dy))
 	    return y;
 	if (isinf(dx))
-	    return big_fdiv(x, y);
+	    return big_fdiv_float(x, y);
 	break;
 
       default:

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

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