summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-04 16:10:06 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-04 16:10:06 +0000
commit8f8bf8243d810d49a98dcb2713b14de3bf3716e0 (patch)
treec6abe5461a6b3c784d613a9284ca9a583170d8fd /ext
parentff5a4c998340eff7c3d6867836d387d7a5159dec (diff)
* 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
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/bignum/depend1
-rw-r--r--ext/-test-/bignum/div.c25
2 files changed, 26 insertions, 0 deletions
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);
+}