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

ruby-changes:30795

From: nobu <ko1@a...>
Date: Sun, 8 Sep 2013 04:04:42 +0900 (JST)
Subject: [ruby-changes:30795] nobu:r42874 (trunk): bignum.c, math.c: RB_BIGNUM_TYPE_P

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

  New Revision: 42874

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

  Log:
    bignum.c, math.c: RB_BIGNUM_TYPE_P
    
    * bignum.c, math.c (RB_BIGNUM_TYPE_P): predicate macro like
      RB_FLOAT_TYPE_P.

  Modified files:
    trunk/bignum.c
    trunk/math.c
Index: math.c
===================================================================
--- math.c	(revision 42873)
+++ math.c	(revision 42874)
@@ -20,6 +20,8 @@ https://github.com/ruby/ruby/blob/trunk/math.c#L20
     extern int signbit(double);
 #endif
 
+#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
+
 VALUE rb_mMath;
 VALUE rb_eMathDomainError;
 
@@ -444,7 +446,7 @@ math_log(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/math.c#L446
 
     rb_scan_args(argc, argv, "11", &x, &base);
 
-    if (RB_TYPE_P(x, T_BIGNUM) && RBIGNUM_POSITIVE_P(x) &&
+    if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
             DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
         numbits -= DBL_MANT_DIG;
         x = rb_big_rshift(x, SIZET2NUM(numbits));
@@ -501,7 +503,7 @@ math_log2(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L503
     double d0, d;
     size_t numbits = 0;
 
-    if (RB_TYPE_P(x, T_BIGNUM) && RBIGNUM_POSITIVE_P(x) &&
+    if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
             DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
         numbits -= DBL_MANT_DIG;
         x = rb_big_rshift(x, SIZET2NUM(numbits));
@@ -540,7 +542,7 @@ math_log10(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L542
     double d0, d;
     size_t numbits = 0;
 
-    if (RB_TYPE_P(x, T_BIGNUM) && RBIGNUM_POSITIVE_P(x) &&
+    if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
             DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
         numbits -= DBL_MANT_DIG;
         x = rb_big_rshift(x, SIZET2NUM(numbits));
Index: bignum.c
===================================================================
--- bignum.c	(revision 42873)
+++ bignum.c	(revision 42874)
@@ -30,6 +30,8 @@ https://github.com/ruby/ruby/blob/trunk/bignum.c#L30
 #include <gmp.h>
 #endif
 
+#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
+
 VALUE rb_cBignum;
 const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 
@@ -2920,7 +2922,7 @@ rb_cmpint(VALUE val, VALUE a, VALUE b) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2922
         if (l < 0) return -1;
         return 0;
     }
-    if (RB_TYPE_P(val, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(val)) {
 	if (BIGZEROP(val)) return 0;
 	if (RBIGNUM_SIGN(val)) return 1;
 	return -1;
@@ -3129,7 +3131,7 @@ bigfixize(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L3131
 static VALUE
 bignorm(VALUE x)
 {
-    if (RB_TYPE_P(x, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(x)) {
 	x = bigfixize(x);
     }
     return x;
@@ -5394,7 +5396,7 @@ rb_big_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5396
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
     }
     else if (RB_FLOAT_TYPE_P(y)) {
         return rb_integer_float_cmp(x, y);
@@ -5426,7 +5428,7 @@ big_op(VALUE x, VALUE y, enum big_op_t o https://github.com/ruby/ruby/blob/trunk/bignum.c#L5428
     VALUE rel;
     int n;
 
-    if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM)) {
+    if (FIXNUM_P(y) || RB_BIGNUM_TYPE_P(y)) {
 	rel = rb_big_cmp(x, y);
     }
     else if (RB_FLOAT_TYPE_P(y)) {
@@ -5529,7 +5531,7 @@ rb_big_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5531
 	if (bignorm(x) == y) return Qtrue;
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
     }
     else if (RB_FLOAT_TYPE_P(y)) {
         return rb_integer_float_eq(x, y);
@@ -5557,7 +5559,7 @@ rb_big_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5559
 VALUE
 rb_big_eql(VALUE x, VALUE y)
 {
-    if (!RB_TYPE_P(y, T_BIGNUM)) return Qfalse;
+    if (!RB_BIGNUM_TYPE_P(y)) return Qfalse;
     if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y)) return Qfalse;
     if (RBIGNUM_LEN(x) != RBIGNUM_LEN(y)) return Qfalse;
     if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM_LEN(y)) != 0) return Qfalse;
@@ -5878,7 +5880,7 @@ rb_big_plus(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5880
 	}
 	return bigadd_int(x, n);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	return bignorm(bigadd(x, y, 1));
     }
     else if (RB_FLOAT_TYPE_P(y)) {
@@ -5914,7 +5916,7 @@ rb_big_minus(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5916
 	}
 	return bigsub_int(x, n);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	return bignorm(bigadd(x, y, 0));
     }
     else if (RB_FLOAT_TYPE_P(y)) {
@@ -5996,7 +5998,7 @@ rb_big_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5998
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
     }
     else if (RB_FLOAT_TYPE_P(y)) {
 	return DBL2NUM(rb_big2dbl(x) * RFLOAT_VALUE(y));
@@ -6125,7 +6127,7 @@ rb_big_divide(VALUE x, VALUE y, ID op) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6127
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
     }
     else if (RB_FLOAT_TYPE_P(y)) {
 	if (op == '/') {
@@ -6190,7 +6192,7 @@ rb_big_modulo(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6192
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (!RB_TYPE_P(y, T_BIGNUM)) {
+    else if (!RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bin(x, y, '%');
     }
     bigdivmod(x, y, 0, &z);
@@ -6215,7 +6217,7 @@ rb_big_remainder(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6217
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (!RB_TYPE_P(y, T_BIGNUM)) {
+    else if (!RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bin(x, y, rb_intern("remainder"));
     }
     bigdivrem(x, y, 0, &z);
@@ -6238,7 +6240,7 @@ rb_big_divmod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6240
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (!RB_TYPE_P(y, T_BIGNUM)) {
+    else if (!RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bin(x, y, rb_intern("divmod"));
     }
     bigdivmod(x, y, &div, &mod);
@@ -6325,7 +6327,7 @@ rb_big_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6327
 	if (isinf(dx))
 	    return big_fdiv_int(x, rb_int2big(FIX2LONG(y)));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	dy = rb_big2dbl(y);
 	if (isinf(dx) || isinf(dy))
 	    return big_fdiv_int(x, y);
@@ -6369,7 +6371,7 @@ rb_big_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6371
 	if ((!RBIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d))
 	    return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	y = bignorm(y);
 	if (FIXNUM_P(y))
 	    goto again;
@@ -6484,7 +6486,7 @@ rb_big_and(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6486
     BDIGIT tmph;
     long tmpn;
 
-    if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
+    if (!FIXNUM_P(y) && !RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bit(x, y, '&');
     }
 
@@ -6610,7 +6612,7 @@ rb_big_or(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6612
     BDIGIT tmph;
     long tmpn;
 
-    if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
+    if (!FIXNUM_P(y) && !RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bit(x, y, '|');
     }
 
@@ -6710,7 +6712,7 @@ rb_big_xor(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6712
     BDIGIT tmph;
     long tmpn;
 
-    if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
+    if (!FIXNUM_P(y) && !RB_BIGNUM_TYPE_P(y)) {
 	return rb_num_coerce_bit(x, y, '^');
     }
 
@@ -6776,7 +6778,7 @@ rb_big_lshift(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6778
             shift_numdigits = shift >> bit_length(BITSPERDIG-1);
             return bignorm(big_shift3(x, lshift_p, shift_numdigits, shift_numbits));
 	}
-	else if (RB_TYPE_P(y, T_BIGNUM)) {
+	else if (RB_BIGNUM_TYPE_P(y)) {
             return bignorm(big_shift2(x, 1, y));
 	}
 	y = rb_to_int(y);
@@ -6814,7 +6816,7 @@ rb_big_rshift(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6816
             shift_numdigits = shift >> bit_length(BITSPERDIG-1);
             return bignorm(big_shift3(x, lshift_p, shift_numdigits, shift_numbits));
 	}
-	else if (RB_TYPE_P(y, T_BIGNUM)) {
+	else if (RB_BIGNUM_TYPE_P(y)) {
             return bignorm(big_shift2(x, 0, y));
 	}
 	y = rb_to_int(y);
@@ -6848,7 +6850,7 @@ rb_big_aref(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6850
     long i, s1, s2;
     BDIGIT bit;
 
-    if (RB_TYPE_P(y, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(y)) {
 	if (!RBIGNUM_SIGN(y))
 	    return INT2FIX(0);
 	bigtrunc(y);
@@ -6916,7 +6918,7 @@ rb_big_coerce(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6918
     if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
-    else if (!RB_TYPE_P(y, T_BIGNUM)) {
+    else if (!RB_BIGNUM_TYPE_P(y)) {
 	rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
 		 rb_obj_classname(y));
     }

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

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