1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/bigdecimal/bigdecimal.c (BigDecimal_to_s): use CRuby style.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2013-01-14 05:42:51 +00:00
parent 512b987544
commit a4665e30f7
2 changed files with 45 additions and 30 deletions

View file

@ -1,3 +1,7 @@
Mon Jan 14 14:41:00 2013 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_s): use CRuby style.
Mon Jan 14 14:39:00 2013 Kenta Murata <mrkn@mrkn.jp> Mon Jan 14 14:39:00 2013 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.c: use `RB_TYPE_P(x, t)` instead of * ext/bigdecimal/bigdecimal.c: use `RB_TYPE_P(x, t)` instead of

View file

@ -1840,8 +1840,8 @@ static VALUE
BigDecimal_to_s(int argc, VALUE *argv, VALUE self) BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
{ {
ENTER(5); ENTER(5);
int fmt=0; /* 0:E format */ int fmt = 0; /* 0:E format */
int fPlus=0; /* =0:default,=1: set ' ' before digits ,set '+' before digits. */ int fPlus = 0; /* =0:default,=1: set ' ' before digits ,set '+' before digits. */
Real *vp; Real *vp;
volatile VALUE str; volatile VALUE str;
char *psz; char *psz;
@ -1851,19 +1851,26 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
GUARD_OBJ(vp,GetVpValue(self,1)); GUARD_OBJ(vp,GetVpValue(self,1));
if(rb_scan_args(argc,argv,"01",&f)==1) { if (rb_scan_args(argc,argv,"01",&f)==1) {
if (RB_TYPE_P(f, T_STRING)) { if (RB_TYPE_P(f, T_STRING)) {
SafeStringValue(f); SafeStringValue(f);
psz = RSTRING_PTR(f); psz = RSTRING_PTR(f);
if(*psz==' ') { if (*psz == ' ') {
fPlus = 1; psz++; fPlus = 1;
} else if(*psz=='+') { psz++;
fPlus = 2; psz++; }
else if (*psz == '+') {
fPlus = 2;
psz++;
}
while ((ch = *psz++) != 0) {
if (ISSPACE(ch)) {
continue;
}
if (!ISDIGIT(ch)) {
if (ch == 'F' || ch == 'f') {
fmt = 1; /* F format */
} }
while((ch=*psz++)!=0) {
if(ISSPACE(ch)) continue;
if(!ISDIGIT(ch)) {
if(ch=='F' || ch=='f') fmt = 1; /* F format */
break; break;
} }
mc = mc * 10 + ch - '0'; mc = mc * 10 + ch - '0';
@ -1873,19 +1880,23 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
mc = (size_t)GetPositiveInt(f); mc = (size_t)GetPositiveInt(f);
} }
} }
if(fmt) { if (fmt) {
nc = VpNumOfChars(vp,"F"); nc = VpNumOfChars(vp, "F");
} else { }
nc = VpNumOfChars(vp,"E"); else {
nc = VpNumOfChars(vp, "E");
}
if (mc > 0) {
nc += (nc + mc - 1) / mc + 1;
} }
if(mc>0) nc += (nc + mc - 1) / mc + 1;
str = rb_str_new(0, nc); str = rb_str_new(0, nc);
psz = RSTRING_PTR(str); psz = RSTRING_PTR(str);
if(fmt) { if (fmt) {
VpToFString(vp, psz, mc, fPlus); VpToFString(vp, psz, mc, fPlus);
} else { }
else {
VpToString (vp, psz, mc, fPlus); VpToString (vp, psz, mc, fPlus);
} }
rb_str_resize(str, strlen(psz)); rb_str_resize(str, strlen(psz));