* 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
This commit is contained in:
parent
a426373520
commit
93283e7552
@ -1,3 +1,10 @@
|
|||||||
|
Wed Nov 26 03:17:48 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Wed Nov 26 03:00:59 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* ext/bigdecimal/bigdecimal.c (VpAlloc): avoid ALLOCA_N() to avoid
|
* ext/bigdecimal/bigdecimal.c (VpAlloc): avoid ALLOCA_N() to avoid
|
||||||
|
@ -521,6 +521,18 @@ BigDecimal_IsFinite(VALUE self)
|
|||||||
return Qtrue;
|
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).
|
/* Returns the value as an integer (Fixnum or Bignum).
|
||||||
*
|
*
|
||||||
* If the BigNumber is infinity or NaN, returns nil.
|
* If the BigNumber is infinity or NaN, returns nil.
|
||||||
@ -536,18 +548,7 @@ BigDecimal_to_i(VALUE self)
|
|||||||
Real *p;
|
Real *p;
|
||||||
|
|
||||||
GUARD_OBJ(p,GetVpValue(self,1));
|
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);
|
e = VpExponent10(p);
|
||||||
if(e<=0) return INT2FIX(0);
|
if(e<=0) return INT2FIX(0);
|
||||||
@ -625,6 +626,8 @@ BigDecimal_to_r(VALUE self)
|
|||||||
VALUE a, digits, numerator;
|
VALUE a, digits, numerator;
|
||||||
|
|
||||||
p = GetVpValue(self,1);
|
p = GetVpValue(self,1);
|
||||||
|
BigDecimal_check_num(p);
|
||||||
|
|
||||||
sign = VpGetSign(p);
|
sign = VpGetSign(p);
|
||||||
power = VpExponent10(p);
|
power = VpExponent10(p);
|
||||||
a = BigDecimal_split(self);
|
a = BigDecimal_split(self);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user