summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-01 15:00:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-01 15:00:01 +0000
commitb5f2df6b9e4540c87b873f86883d48e99263e890 (patch)
treeaca643f973ceda31e34e35d7df49bfefeaf68061 /numeric.c
parent582983c224f6ef199040ddd2b1bc106d901403b4 (diff)
* bignum.c (rb_big_divide), numeric.c (fix_divide): check for result
domain. [ruby-dev:34559] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/numeric.c b/numeric.c
index 67ef22a..0ae4bb0 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2249,7 +2249,7 @@ fix_fdiv(VALUE x, VALUE y)
}
static VALUE
-fix_divide(VALUE x, VALUE y, int flo)
+fix_divide(VALUE x, VALUE y, ID op)
{
if (FIXNUM_P(y)) {
long div;
@@ -2262,15 +2262,17 @@ fix_divide(VALUE x, VALUE y, int flo)
x = rb_int2big(FIX2LONG(x));
return rb_big_div(x, y);
case T_FLOAT:
- if (flo) {
- return DOUBLE2NUM((double)FIX2LONG(x) / RFLOAT_VALUE(y));
- }
- else {
- long div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
- return LONG2NUM(div);
+ {
+ double div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
+ if (op == '/') {
+ return DOUBLE2NUM(div);
+ }
+ else {
+ return rb_dbl2big(div);
+ }
}
default:
- return rb_num_coerce_bin(x, y, flo ? '/' : rb_intern("div"));
+ return rb_num_coerce_bin(x, y, op);
}
}
@@ -2286,7 +2288,7 @@ fix_divide(VALUE x, VALUE y, int flo)
static VALUE
fix_div(VALUE x, VALUE y)
{
- return fix_divide(x, y, Qtrue);
+ return fix_divide(x, y, '/');
}
/*
@@ -2299,7 +2301,7 @@ fix_div(VALUE x, VALUE y)
static VALUE
fix_idiv(VALUE x, VALUE y)
{
- return fix_divide(x, y, Qfalse);
+ return fix_divide(x, y, rb_intern("div"));
}
/*