summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-25 18:19:07 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-25 18:19:07 +0000
commit93283e75529ad1b9ec3f2b302d5e43c394863af3 (patch)
treeb25ce5d13b1c117973d8cfcbbc1f02ab1885f42e /ext
parenta426373520a0d633b23be87425b05ac86ed45127 (diff)
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_r): raise exception
for nan/inf conversion. [ruby-dev:37187] fix #793 * ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 19aeb2e0c1..66ab12bca6 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -521,6 +521,18 @@ BigDecimal_IsFinite(VALUE self)
return Qtrue;
}
+static void
+BigDecimal_check_num(Real *p)
+{
+ if(VpIsNaN(p)) {
+ VpException(VP_EXCEPTION_NaN,"Computation results to 'NaN'(Not a Number)",1);
+ } else if(VpIsPosInf(p)) {
+ VpException(VP_EXCEPTION_INFINITY,"Computation results to 'Infinity'",1);
+ } else if(VpIsNegInf(p)) {
+ VpException(VP_EXCEPTION_INFINITY,"Computation results to '-Infinity'",1);
+ }
+}
+
/* Returns the value as an integer (Fixnum or Bignum).
*
* If the BigNumber is infinity or NaN, returns nil.
@@ -536,18 +548,7 @@ BigDecimal_to_i(VALUE self)
Real *p;
GUARD_OBJ(p,GetVpValue(self,1));
-
- /* Infinity or NaN not converted. */
- if(VpIsNaN(p)) {
- VpException(VP_EXCEPTION_NaN,"Computation results to 'NaN'(Not a Number)",1);
- return Qnil; /* not reached */
- } else if(VpIsPosInf(p)) {
- VpException(VP_EXCEPTION_INFINITY,"Computation results to 'Infinity'",1);
- return Qnil; /* not reached */
- } else if(VpIsNegInf(p)) {
- VpException(VP_EXCEPTION_INFINITY,"Computation results to '-Infinity'",1);
- return Qnil; /* not reached */
- }
+ BigDecimal_check_num(p);
e = VpExponent10(p);
if(e<=0) return INT2FIX(0);
@@ -625,6 +626,8 @@ BigDecimal_to_r(VALUE self)
VALUE a, digits, numerator;
p = GetVpValue(self,1);
+ BigDecimal_check_num(p);
+
sign = VpGetSign(p);
power = VpExponent10(p);
a = BigDecimal_split(self);