ruby-changes:8824
From: matz <ko1@a...>
Date: Wed, 26 Nov 2008 03:19:27 +0900 (JST)
Subject: [ruby-changes:8824] Ruby:r20360 (trunk): * ext/bigdecimal/bigdecimal.c (BigDecimal_to_r): raise exception
matz 2008-11-26 03:19:07 +0900 (Wed, 26 Nov 2008) New Revision: 20360 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20360 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/bigdecimal/bigdecimal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 20359) +++ ChangeLog (revision 20360) @@ -1,3 +1,10 @@ +Wed Nov 26 03:17:48 2008 Yukihiro Matsumoto <matz@r...> + + * 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. + Wed Nov 26 03:00:59 2008 Yukihiro Matsumoto <matz@r...> * ext/bigdecimal/bigdecimal.c (VpAlloc): avoid ALLOCA_N() to avoid Index: ext/bigdecimal/bigdecimal.c =================================================================== --- ext/bigdecimal/bigdecimal.c (revision 20359) +++ ext/bigdecimal/bigdecimal.c (revision 20360) @@ -521,6 +521,18 @@ 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,19 +548,8 @@ Real *p; GUARD_OBJ(p,GetVpValue(self,1)); + BigDecimal_check_num(p); - /* 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 */ - } - e = VpExponent10(p); if(e<=0) return INT2FIX(0); nf = VpBaseFig(); @@ -625,6 +626,8 @@ VALUE a, digits, numerator; p = GetVpValue(self,1); + BigDecimal_check_num(p); + sign = VpGetSign(p); power = VpExponent10(p); a = BigDecimal_split(self); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/