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

ruby-changes:44637

From: mrkn <ko1@a...>
Date: Fri, 11 Nov 2016 23:57:03 +0900 (JST)
Subject: [ruby-changes:44637] mrkn:r56707 (trunk): numeric.c, rational.c: refactor by using FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P

mrkn	2016-11-11 23:39:25 +0900 (Fri, 11 Nov 2016)

  New Revision: 56707

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56707

  Log:
    numeric.c, rational.c: refactor by using FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P
    
    * numeric.c (num_zero_p, fix_divide, fix_mod, fix_divmod): refactor by using
      FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P.
    
    * rational.c (INT_NEGATIVE_P, INT_ZERO_P): ditto.
    
    * internal.h: move FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P from numeric.c

  Modified files:
    trunk/internal.h
    trunk/numeric.c
    trunk/rational.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 56706)
+++ numeric.c	(revision 56707)
@@ -262,8 +262,6 @@ compare_with_zero(VALUE num, ID mid) https://github.com/ruby/ruby/blob/trunk/numeric.c#L262
 }
 
 #define FIXNUM_POSITIVE_P(num) ((SIGNED_VALUE)(num) > (SIGNED_VALUE)INT2FIX(0))
-#define FIXNUM_NEGATIVE_P(num) ((SIGNED_VALUE)(num) < 0)
-#define FIXNUM_ZERO_P(num) ((num) == INT2FIX(0))
 
 static inline int
 int_pos_p(VALUE num)
@@ -784,7 +782,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L782
 num_zero_p(VALUE num)
 {
     if (FIXNUM_P(num)) {
-	if (FIX2LONG(num) == 0) {
+	if (FIXNUM_ZERO_P(num)) {
 	    return Qtrue;
 	}
     }
@@ -3608,7 +3606,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L3606
 fix_divide(VALUE x, VALUE y, ID op)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(y) == 0) rb_num_zerodiv();
+	if (FIXNUM_ZERO_P(y)) rb_num_zerodiv();
 	return rb_fix_div_fix(x, y);
     }
     else if (RB_TYPE_P(y, T_BIGNUM)) {
@@ -3699,7 +3697,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L3697
 fix_mod(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (FIX2LONG(y) == 0) rb_num_zerodiv();
+	if (FIXNUM_ZERO_P(y)) rb_num_zerodiv();
 	return rb_fix_mod_fix(x, y);
     }
     else if (RB_TYPE_P(y, T_BIGNUM)) {
@@ -3772,7 +3770,7 @@ fix_divmod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3770
 {
     if (FIXNUM_P(y)) {
 	VALUE div, mod;
-	if (FIX2LONG(y) == 0) rb_num_zerodiv();
+	if (FIXNUM_ZERO_P(y)) rb_num_zerodiv();
 	rb_fix_divmod_fix(x, y, &div, &mod);
 	return rb_assoc_new(div, mod);
     }
Index: internal.h
===================================================================
--- internal.h	(revision 56706)
+++ internal.h	(revision 56707)
@@ -1136,6 +1136,10 @@ VALUE rb_math_sqrt(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1136
 void Init_newline(void);
 
 /* numeric.c */
+
+#define FIXNUM_NEGATIVE_P(num) ((SIGNED_VALUE)(num) < 0)
+#define FIXNUM_ZERO_P(num) ((num) == INT2FIX(0))
+
 #ifndef ROUND_DEFAULT
 # define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_EVEN
 #endif
Index: rational.c
===================================================================
--- rational.c	(revision 56706)
+++ rational.c	(revision 56707)
@@ -27,8 +27,8 @@ https://github.com/ruby/ruby/blob/trunk/rational.c#L27
 
 #define GMP_GCD_DIGITS 1
 
-#define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? ((SIGNED_VALUE)(x) < 0) : BIGNUM_NEGATIVE_P(x))
-#define INT_ZERO_P(x) (FIXNUM_P(x) ? (FIX2LONG(x) == 0) : rb_bigzero_p(x))
+#define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
+#define INT_ZERO_P(x) (FIXNUM_P(x) ? FIXNUM_ZERO_P(x) : rb_bigzero_p(x))
 
 VALUE rb_cRational;
 

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

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