ruby-changes:8881
From: yugui <ko1@a...>
Date: Sun, 30 Nov 2008 18:25:26 +0900 (JST)
Subject: [ruby-changes:8881] Ruby:r20417 (ruby_1_9_1): merges r20360 from trunk into ruby_1_9_1.
yugui 2008-11-30 18:24:03 +0900 (Sun, 30 Nov 2008) New Revision: 20417 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20417 Log: merges r20360 from trunk into ruby_1_9_1. * 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: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/ext/bigdecimal/bigdecimal.c Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20416) +++ ruby_1_9_1/ChangeLog (revision 20417) @@ -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: ruby_1_9_1/ext/bigdecimal/bigdecimal.c =================================================================== --- ruby_1_9_1/ext/bigdecimal/bigdecimal.c (revision 20416) +++ ruby_1_9_1/ext/bigdecimal/bigdecimal.c (revision 20417) @@ -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/