1 #include "internal.h"
2 
3 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
4 static VALUE
big(VALUE x)5 big(VALUE x)
6 {
7     if (FIXNUM_P(x))
8         return rb_int2big(FIX2LONG(x));
9     if (RB_TYPE_P(x, T_BIGNUM))
10         return x;
11     rb_raise(rb_eTypeError, "can't convert %s to Bignum",
12             rb_obj_classname(x));
13 }
14 #endif
15 
16 static VALUE
gcd_normal(VALUE x,VALUE y)17 gcd_normal(VALUE x, VALUE y)
18 {
19     return rb_big_norm(rb_gcd_normal(rb_to_int(x), rb_to_int(y)));
20 }
21 
22 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
23 static VALUE
gcd_gmp(VALUE x,VALUE y)24 gcd_gmp(VALUE x, VALUE y)
25 {
26     return rb_big_norm(rb_gcd_gmp(big(x), big(y)));
27 }
28 #else
29 #define gcd_gmp rb_f_notimplement
30 #endif
31 
32 void
Init_rational(VALUE klass)33 Init_rational(VALUE klass)
34 {
35     rb_define_method(rb_cInteger, "gcd_normal", gcd_normal, 1);
36     rb_define_method(rb_cInteger, "gcd_gmp", gcd_gmp, 1);
37 }
38