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

ruby-changes:26757

From: mrkn <ko1@a...>
Date: Mon, 14 Jan 2013 14:43:00 +0900 (JST)
Subject: [ruby-changes:26757] mrkn:r38809 (trunk): * ext/bigdecimal/bigdecimal.c: use `RB_TYPE_P(x, t)` instead of

mrkn	2013-01-14 14:42:48 +0900 (Mon, 14 Jan 2013)

  New Revision: 38809

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

  Log:
    * ext/bigdecimal/bigdecimal.c: use `RB_TYPE_P(x, t)` instead of
      `TYPE(x) == t`.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38808)
+++ ChangeLog	(revision 38809)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan 14 14:39:00 2013  Kenta Murata  <mrkn@m...>
+
+	* ext/bigdecimal/bigdecimal.c: use `RB_TYPE_P(x, t)` instead of
+	  `TYPE(x) == t`.
+
 Mon Jan 14 10:18:56 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* enumerator.c: Fix size for Enumerator::Lazy#flat_map
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 38808)
+++ ext/bigdecimal/bigdecimal.c	(revision 38809)
@@ -674,7 +674,7 @@ BigDecimal_to_i(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L674
 	    ret = rb_funcall(numerator, '*', 1,
 			     rb_funcall(INT2FIX(10), rb_intern("**"), 1,
 					INT2FIX(dpower)));
-	if (TYPE(ret) == T_FLOAT)
+	if (RB_TYPE_P(ret, T_FLOAT))
 	    rb_raise(rb_eFloatDomainError, "Infinity");
 	return ret;
     }
@@ -784,11 +784,11 @@ BigDecimal_coerce(VALUE self, VALUE othe https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L784
     VALUE obj;
     Real *b;
 
-    if (TYPE(other) == T_FLOAT) {
+    if (RB_TYPE_P(other, T_FLOAT)) {
 	obj = rb_assoc_new(other, BigDecimal_to_f(self));
     }
     else {
-	if (TYPE(other) == T_RATIONAL) {
+	if (RB_TYPE_P(other, T_RATIONAL)) {
 	    Real* pv = DATA_PTR(self);
 	    GUARD_OBJ(b, GetVpValueWithPrec(other, pv->Prec*VpBaseFig(), 1));
 	}
@@ -840,10 +840,10 @@ BigDecimal_add(VALUE self, VALUE r) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L840
     size_t mx;
 
     GUARD_OBJ(a, GetVpValue(self, 1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -894,10 +894,10 @@ BigDecimal_sub(VALUE self, VALUE r) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L894
     size_t mx;
 
     GUARD_OBJ(a,GetVpValue(self,1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -1155,10 +1155,10 @@ BigDecimal_mult(VALUE self, VALUE r) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1155
     size_t mx;
 
     GUARD_OBJ(a,GetVpValue(self,1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -1183,10 +1183,10 @@ BigDecimal_divide(Real **c, Real **res, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1183
     size_t mx;
 
     GUARD_OBJ(a,GetVpValue(self,1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -1258,10 +1258,10 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1258
     size_t mx;
 
     GUARD_OBJ(a,GetVpValue(self,1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -1359,10 +1359,10 @@ BigDecimal_divremain(VALUE self, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1359
     Real *f=NULL;
 
     GUARD_OBJ(a,GetVpValue(self,1));
-    if (TYPE(r) == T_FLOAT) {
+    if (RB_TYPE_P(r, T_FLOAT)) {
 	b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
     }
-    else if (TYPE(r) == T_RATIONAL) {
+    else if (RB_TYPE_P(r, T_RATIONAL)) {
 	b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
     }
     else {
@@ -1852,7 +1852,7 @@ BigDecimal_to_s(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1852
     GUARD_OBJ(vp,GetVpValue(self,1));
 
     if(rb_scan_args(argc,argv,"01",&f)==1) {
-        if(TYPE(f)==T_STRING) {
+	if (RB_TYPE_P(f, T_STRING)) {
             SafeStringValue(f);
             psz = RSTRING_PTR(f);
             if(*psz==' ') {
@@ -2003,7 +2003,7 @@ static VALUE BigMath_s_log(VALUE, VALUE, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2003
 inline static int
 is_integer(VALUE x)
 {
-    return (TYPE(x) == T_FIXNUM || TYPE(x) == T_BIGNUM);
+    return (RB_TYPE_P(x, T_FIXNUM) || RB_TYPE_P(x, T_BIGNUM));
 }
 
 inline static int
@@ -2012,10 +2012,10 @@ is_negative(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2012
     if (FIXNUM_P(x)) {
 	return FIX2LONG(x) < 0;
     }
-    else if (TYPE(x) == T_BIGNUM) {
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
 	return RBIGNUM_NEGATIVE_P(x);
     }
-    else if (TYPE(x) == T_FLOAT) {
+    else if (RB_TYPE_P(x, T_FLOAT)) {
 	return RFLOAT_VALUE(x) < 0.0;
     }
     return RTEST(rb_funcall(x, '<', 1, INT2FIX(0)));
@@ -2278,7 +2278,7 @@ retry: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2278
     if (exp != NULL) {
 	return rmpd_power_by_big_decimal(x, exp, n);
     }
-    else if (TYPE(vexp) == T_BIGNUM) {
+    else if (RB_TYPE_P(vexp, T_BIGNUM)) {
 	VALUE abs_value = BigDecimal_abs(self);
 	if (is_one(abs_value)) {
 	    return ToValue(VpCreateRbObject(n, "1"));
@@ -2752,7 +2752,7 @@ BigMath_s_log(VALUE klass, VALUE x, VALU https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2752
     double flo;
     long fix;
 
-    if (TYPE(vprec) != T_FIXNUM && TYPE(vprec) != T_BIGNUM) {
+    if (!is_integer(vprec)) {
 	rb_raise(rb_eArgError, "precision must be an Integer");
     }
 

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

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