mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/bigdecimal] Use smallest local variable scope in GetVpValueWithPrec
https://github.com/ruby/bigdecimal/commit/44f26b9aa0
This commit is contained in:
parent
590dc06e38
commit
72d504c1fd
1 changed files with 11 additions and 9 deletions
|
@ -205,10 +205,7 @@ static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise
|
||||||
static Real*
|
static Real*
|
||||||
GetVpValueWithPrec(VALUE v, long prec, int must)
|
GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||||
{
|
{
|
||||||
ENTER(1);
|
|
||||||
Real *pv;
|
Real *pv;
|
||||||
VALUE bg;
|
|
||||||
char szD[128];
|
|
||||||
|
|
||||||
switch(TYPE(v)) {
|
switch(TYPE(v)) {
|
||||||
case T_FLOAT: {
|
case T_FLOAT: {
|
||||||
|
@ -233,9 +230,11 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_FIXNUM:
|
case T_FIXNUM: {
|
||||||
|
char szD[128];
|
||||||
sprintf(szD, "%ld", FIX2LONG(v));
|
sprintf(szD, "%ld", FIX2LONG(v));
|
||||||
return VpCreateRbObject(VpBaseFig() * 2 + 1, szD, true);
|
return VpCreateRbObject(VpBaseFig() * 2 + 1, szD, true);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_NUMERIC_STRING
|
#ifdef ENABLE_NUMERIC_STRING
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
|
@ -244,11 +243,14 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||||
RSTRING_PTR(v), true);
|
RSTRING_PTR(v), true);
|
||||||
#endif /* ENABLE_NUMERIC_STRING */
|
#endif /* ENABLE_NUMERIC_STRING */
|
||||||
|
|
||||||
case T_BIGNUM:
|
case T_BIGNUM: {
|
||||||
bg = rb_big2str(v, 10);
|
VALUE bg = rb_big2str(v, 10);
|
||||||
PUSH(bg);
|
pv = VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
|
||||||
return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
|
|
||||||
RSTRING_PTR(bg), true);
|
RSTRING_PTR(bg), true);
|
||||||
|
RB_GC_GUARD(bg);
|
||||||
|
return pv;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto SomeOneMayDoIt;
|
goto SomeOneMayDoIt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue