summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/bigdecimal.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 16:08:38 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 16:08:38 +0000
commitc2f9e1b1007c1d498fed23bc749305b3c47afea1 (patch)
treef1d911d11863566b47c178a32e14a84304631f65 /ext/bigdecimal/bigdecimal.c
parent14c504b3cc974e31fd0cdca8bfb654ddba4906be (diff)
* ext/bigdecimal (BigDecimal_to_i): Integer#** may return flonum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r--ext/bigdecimal/bigdecimal.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 353210b..388dbbd 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -564,19 +564,24 @@ BigDecimal_to_i(VALUE self)
VALUE a = BigDecimal_split(self);
VALUE digits = RARRAY_PTR(a)[1];
VALUE numerator = rb_funcall(digits, rb_intern("to_i"), 0);
+ VALUE ret;
ssize_t dpower = e - (ssize_t)RSTRING_LEN(digits);
if (VpGetSign(p) < 0) {
numerator = rb_funcall(numerator, '*', 1, INT2FIX(-1));
}
if (dpower < 0) {
- return rb_funcall(numerator, rb_intern("div"), 1,
+ ret = rb_funcall(numerator, rb_intern("div"), 1,
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
INT2FIX(-dpower)));
}
- return rb_funcall(numerator, '*', 1,
- rb_funcall(INT2FIX(10), rb_intern("**"), 1,
- INT2FIX(dpower)));
+ else
+ ret = rb_funcall(numerator, '*', 1,
+ rb_funcall(INT2FIX(10), rb_intern("**"), 1,
+ INT2FIX(dpower)));
+ if (TYPE(ret) == T_FLOAT)
+ rb_raise(rb_eFloatDomainError, "Infinity");
+ return ret;
}
}