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*
|
||||
GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||
{
|
||||
ENTER(1);
|
||||
Real *pv;
|
||||
VALUE bg;
|
||||
char szD[128];
|
||||
|
||||
switch(TYPE(v)) {
|
||||
case T_FLOAT: {
|
||||
|
@ -233,9 +230,11 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
|
|||
}
|
||||
break;
|
||||
|
||||
case T_FIXNUM:
|
||||
case T_FIXNUM: {
|
||||
char szD[128];
|
||||
sprintf(szD, "%ld", FIX2LONG(v));
|
||||
return VpCreateRbObject(VpBaseFig() * 2 + 1, szD, true);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NUMERIC_STRING
|
||||
case T_STRING:
|
||||
|
@ -244,11 +243,14 @@ GetVpValueWithPrec(VALUE v, long prec, int must)
|
|||
RSTRING_PTR(v), true);
|
||||
#endif /* ENABLE_NUMERIC_STRING */
|
||||
|
||||
case T_BIGNUM:
|
||||
bg = rb_big2str(v, 10);
|
||||
PUSH(bg);
|
||||
return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
|
||||
RSTRING_PTR(bg), true);
|
||||
case T_BIGNUM: {
|
||||
VALUE bg = rb_big2str(v, 10);
|
||||
pv = VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
|
||||
RSTRING_PTR(bg), true);
|
||||
RB_GC_GUARD(bg);
|
||||
return pv;
|
||||
}
|
||||
|
||||
default:
|
||||
goto SomeOneMayDoIt;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue