summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-23 06:22:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-23 06:22:50 +0000
commita9ec8adff324bffa6f3cd18620b674e5737ce0bc (patch)
treefa8ac7f3dd7ae1d12349e43bc3f4c47510fc907a /bignum.c
parent259ba31d8a9bde12f412ba500d80180022d7416e (diff)
downloadruby-a9ec8adff324bffa6f3cd18620b674e5737ce0bc.tar.gz
* lib/rational.rb: modified to support "quo".
* numeric.c (num_quo): should return most exact quotient value, i.e. float by default, rational if available. * numeric.c (num_div): "div" should return x.divmod(x)[0]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/bignum.c b/bignum.c
index 16cb8e1602..2312474c3e 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1284,7 +1284,6 @@ rb_big_div(x, y)
return bignorm(z);
}
-
static VALUE
rb_big_modulo(x, y)
VALUE x, y;
@@ -1351,6 +1350,32 @@ rb_big_divmod(x, y)
return rb_assoc_new(bignorm(div), bignorm(mod));
}
+static VALUE
+rb_big_quo(x, y)
+ VALUE x, y;
+{
+ double dx = rb_big2dbl(x);
+ double dy;
+
+ switch (TYPE(y)) {
+ case T_FIXNUM:
+ dy = (double)FIX2LONG(y);
+ break;
+
+ case T_BIGNUM:
+ dy = rb_big2dbl(y);
+ break;
+
+ case T_FLOAT:
+ dy = RFLOAT(y)->value;
+ break;
+
+ default:
+ return rb_num_coerce_bin(x, y);
+ }
+ return rb_float_new(dx / dy);
+}
+
VALUE
rb_big_pow(x, y)
VALUE x, y;
@@ -1739,6 +1764,7 @@ Init_Bignum()
rb_define_method(rb_cBignum, "divmod", rb_big_divmod, 1);
rb_define_method(rb_cBignum, "modulo", rb_big_modulo, 1);
rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
+ rb_define_method(rb_cBignum, "quo", rb_big_quo, 1);
rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
rb_define_method(rb_cBignum, "&", rb_big_and, 1);
rb_define_method(rb_cBignum, "|", rb_big_or, 1);