| 1 |
#include "internal/numeric.h" |
| 2 |
|
| 3 |
static VALUE |
| 4 |
int_bignum_p(VALUE klass, VALUE self) |
| 5 |
{ |
| 6 |
return RB_TYPE_P(self, T_BIGNUM) ? Qtrue : Qfalse; |
| 7 |
} |
| 8 |
|
| 9 |
static VALUE |
| 10 |
int_fixnum_p(VALUE klass, VALUE self) |
| 11 |
{ |
| 12 |
return FIXNUM_P(self) ? Qtrue : Qfalse; |
| 13 |
} |
| 14 |
|
| 15 |
static VALUE |
| 16 |
rb_int_to_bignum(VALUE klass, VALUE x) |
| 17 |
{ |
| 18 |
if (FIXNUM_P(x)) |
| 19 |
x = rb_int2big(FIX2LONG(x)); |
| 20 |
return x; |
| 21 |
} |
| 22 |
|
| 23 |
static VALUE |
| 24 |
positive_pow(VALUE klass, VALUE x, VALUE y) |
| 25 |
{ |
| 26 |
return rb_int_positive_pow(NUM2LONG(x), NUM2ULONG(y)); |
| 27 |
} |
| 28 |
|
| 29 |
void |
| 30 |
Init_core_ext(VALUE klass) |
| 31 |
{ |
| 32 |
rb_define_singleton_method(klass, "bignum?", int_bignum_p, 1); |
| 33 |
rb_define_singleton_method(klass, "fixnum?", int_fixnum_p, 1); |
| 34 |
rb_define_singleton_method(klass, "to_bignum", rb_int_to_bignum, 1); |
| 35 |
rb_define_singleton_method(klass, "positive_pow", positive_pow, 2); |
| 36 |
} |