From 8f8bf8243d810d49a98dcb2713b14de3bf3716e0 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 4 Sep 2013 16:10:06 +0000 Subject: * bignum.c (rb_big_divrem_normal): New function. * internal.h (rb_big_divrem_normal): Declared. * ext/-test-/bignum/div.c: New file. * test/-ext-/bignum/test_div.rb: New file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/bignum/depend | 1 + ext/-test-/bignum/div.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/-test-/bignum/div.c (limited to 'ext/-test-') diff --git a/ext/-test-/bignum/depend b/ext/-test-/bignum/depend index 4634ecf627..c65482236a 100644 --- a/ext/-test-/bignum/depend +++ b/ext/-test-/bignum/depend @@ -2,5 +2,6 @@ $(OBJS): $(HDRS) $(ruby_headers) intpack.o: intpack.c $(top_srcdir)/internal.h mul.o: mul.c $(top_srcdir)/internal.h +div.o: div.c $(top_srcdir)/internal.h big2str.o: big2str.c $(top_srcdir)/internal.h str2big.o: big2str.c $(top_srcdir)/internal.h diff --git a/ext/-test-/bignum/div.c b/ext/-test-/bignum/div.c new file mode 100644 index 0000000000..1706df99b5 --- /dev/null +++ b/ext/-test-/bignum/div.c @@ -0,0 +1,25 @@ +#include "ruby.h" +#include "internal.h" + +static VALUE +big(VALUE x) +{ + if (FIXNUM_P(x)) + return rb_int2big(FIX2LONG(x)); + if (RB_TYPE_P(x, T_BIGNUM)) + return x; + rb_raise(rb_eTypeError, "can't convert %s to Bignum", + rb_obj_classname(x)); +} + +static VALUE +divrem_normal(VALUE x, VALUE y) +{ + return rb_big_norm(rb_big_divrem_normal(big(x), big(y))); +} + +void +Init_div(VALUE klass) +{ + rb_define_method(rb_cInteger, "big_divrem_normal", divrem_normal, 1); +} -- cgit v1.2.3