From ea6394ef5885fa5d39c13b088d0227fcde85f5cb Mon Sep 17 00:00:00 2001
From: Tadashi Saito <tad.a.digger@gmail.com>
Date: Wed, 4 May 2016 12:34:12 +0900
Subject: [PATCH 1/2] export numeric functions.

* export rb_int_pow() as is
* export flo_pow() as rb_float_pow()
* export int_cmp() as rb_int_cmp()
* export int_equal() as rb_int_equal()
* export int_fdiv() as rb_int_fdiv()
* export rb_int_lshift() as is
* declare rb_int_div() as is
* export int_abs() as rb_int_abs()
---
 internal.h |  8 ++++++++
 numeric.c  | 41 ++++++++++++++++++++---------------------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/internal.h b/internal.h
index 38c7986..27fec2e 100644
--- a/internal.h
+++ b/internal.h
@@ -1104,6 +1104,14 @@ VALUE rb_int2str(VALUE num, int base);
 VALUE rb_dbl_hash(double d);
 VALUE rb_fix_plus(VALUE x, VALUE y);
 VALUE rb_int_ge(VALUE x, VALUE y);
+VALUE rb_int_pow(VALUE x, VALUE y);
+VALUE rb_float_pow(VALUE x, VALUE y);
+VALUE rb_int_cmp(VALUE x, VALUE y);
+VALUE rb_int_equal(VALUE x, VALUE y);
+VALUE rb_int_fdiv(VALUE x, VALUE y);
+VALUE rb_int_lshift(VALUE x, VALUE y);
+VALUE rb_int_div(VALUE x, VALUE y);
+VALUE rb_int_abs(VALUE num);
 
 #if USE_FLONUM
 #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
diff --git a/numeric.c b/numeric.c
index 6c8afe2..9f06e37 100644
--- a/numeric.c
+++ b/numeric.c
@@ -96,7 +96,6 @@ static VALUE fix_mul(VALUE x, VALUE y);
 static VALUE fix_lshift(long, unsigned long);
 static VALUE fix_rshift(long, unsigned long);
 static VALUE int_pow(long x, unsigned long y);
-static VALUE int_cmp(VALUE x, VALUE y);
 static int int_round_zero_p(VALUE num, int ndigits);
 VALUE rb_int_floor(VALUE num, int ndigits);
 VALUE rb_int_ceil(VALUE num, int ndigits);
@@ -1110,8 +1109,8 @@ flo_divmod(VALUE x, VALUE y)
  *    2.0**3      #=> 8.0
  */
 
-static VALUE
-flo_pow(VALUE x, VALUE y)
+VALUE
+rb_float_pow(VALUE x, VALUE y)
 {
     double dx, dy;
     if (RB_TYPE_P(y, T_FIXNUM)) {
@@ -1869,7 +1868,7 @@ rb_int_round(VALUE num, int ndigits)
     h = rb_int_idiv(f, INT2FIX(2));
     r = rb_int_modulo(num, f);
     n = rb_int_minus(num, r);
-    r = int_cmp(r, h);
+    r = rb_int_cmp(r, h);
     if (FIXNUM_POSITIVE_P(r) || (FIXNUM_ZERO_P(r) && !int_neg_p(num))) {
 	n = rb_int_plus(n, f);
     }
@@ -3383,8 +3382,8 @@ fix_fdiv(VALUE x, VALUE y)
     }
 }
 
-static VALUE
-int_fdiv(VALUE x, VALUE y)
+VALUE
+rb_int_fdiv(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x)) {
 	return fix_fdiv(x, y);
@@ -3726,7 +3725,7 @@ fix_pow(VALUE x, VALUE y)
     }
 }
 
-static VALUE
+VALUE
 rb_int_pow(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x)) {
@@ -3768,8 +3767,8 @@ fix_equal(VALUE x, VALUE y)
     }
 }
 
-static VALUE
-int_equal(VALUE x, VALUE y)
+VALUE
+rb_int_equal(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x)) {
 	return fix_equal(x, y);
@@ -3818,8 +3817,8 @@ fix_cmp(VALUE x, VALUE y)
     return rb_num_coerce_cmp(x, y, id_cmp);
 }
 
-static VALUE
-int_cmp(VALUE x, VALUE y)
+VALUE
+rb_int_cmp(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x)) {
 	return fix_cmp(x, y);
@@ -4187,7 +4186,7 @@ fix_lshift(long val, unsigned long width)
     return LONG2NUM(val);
 }
 
-static VALUE
+VALUE
 rb_int_lshift(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x)) {
@@ -4358,8 +4357,8 @@ fix_abs(VALUE fix)
     return LONG2NUM(i);
 }
 
-static VALUE
-int_abs(VALUE num)
+VALUE
+rb_int_abs(VALUE num)
 {
     if (FIXNUM_P(num)) {
 	return fix_abs(num);
@@ -4920,7 +4919,7 @@ Init_Numeric(void)
     rb_define_method(rb_cInteger, "ceil", int_ceil, -1);
     rb_define_method(rb_cInteger, "truncate", int_truncate, -1);
     rb_define_method(rb_cInteger, "round", int_round, -1);
-    rb_define_method(rb_cInteger, "<=>", int_cmp, 1);
+    rb_define_method(rb_cInteger, "<=>", rb_int_cmp, 1);
 
     rb_define_method(rb_cInteger, "-@", rb_int_uminus, 0);
     rb_define_method(rb_cInteger, "+", rb_int_plus, 1);
@@ -4932,14 +4931,14 @@ Init_Numeric(void)
     rb_define_method(rb_cInteger, "modulo", rb_int_modulo, 1);
     rb_define_method(rb_cInteger, "remainder", int_remainder, 1);
     rb_define_method(rb_cInteger, "divmod", int_divmod, 1);
-    rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1);
+    rb_define_method(rb_cInteger, "fdiv", rb_int_fdiv, 1);
     rb_define_method(rb_cInteger, "**", rb_int_pow, 1);
 
-    rb_define_method(rb_cInteger, "abs", int_abs, 0);
-    rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
+    rb_define_method(rb_cInteger, "abs", rb_int_abs, 0);
+    rb_define_method(rb_cInteger, "magnitude", rb_int_abs, 0);
 
-    rb_define_method(rb_cInteger, "===", int_equal, 1);
-    rb_define_method(rb_cInteger, "==", int_equal, 1);
+    rb_define_method(rb_cInteger, "===", rb_int_equal, 1);
+    rb_define_method(rb_cInteger, "==", rb_int_equal, 1);
     rb_define_method(rb_cInteger, ">", int_gt, 1);
     rb_define_method(rb_cInteger, ">=", rb_int_ge, 1);
     rb_define_method(rb_cInteger, "<", int_lt, 1);
@@ -5073,7 +5072,7 @@ Init_Numeric(void)
     rb_define_method(rb_cFloat, "%", flo_mod, 1);
     rb_define_method(rb_cFloat, "modulo", flo_mod, 1);
     rb_define_method(rb_cFloat, "divmod", flo_divmod, 1);
-    rb_define_method(rb_cFloat, "**", flo_pow, 1);
+    rb_define_method(rb_cFloat, "**", rb_float_pow, 1);
     rb_define_method(rb_cFloat, "==", flo_eq, 1);
     rb_define_method(rb_cFloat, "===", flo_eq, 1);
     rb_define_method(rb_cFloat, "<=>", flo_cmp, 1);
-- 
2.8.1

