mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* sprintf.c (rb_f_sprintf): unify output of NaN, Inf and -Inf with
"%f" or etc on all platform. [ruby-dev:23704], [ruby-dev:23747] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
03f3e5e994
commit
ba5b04cd1b
2 changed files with 41 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Jun 22 19:24:59 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* sprintf.c (rb_f_sprintf): unify output of NaN, Inf and -Inf with
|
||||
"%f" or etc on all platform. [ruby-dev:23704], [ruby-dev:23747]
|
||||
|
||||
Tue Jun 22 15:28:12 2004 Michal Rokos <michal@ruby-lang.org>
|
||||
|
||||
* compar.c: Remove explicit NIL_P() checks since rb_cmpint() does it
|
||||
|
|
36
sprintf.c
36
sprintf.c
|
@ -688,6 +688,42 @@ rb_f_sprintf(argc, argv)
|
|||
char fbuf[32];
|
||||
|
||||
fval = RFLOAT(rb_Float(val))->value;
|
||||
if (isnan(fval) || isinf(fval)) {
|
||||
char *expr;
|
||||
|
||||
if (isnan(fval)) {
|
||||
expr = "NaN";
|
||||
}
|
||||
else {
|
||||
expr = "Inf";
|
||||
}
|
||||
need = strlen(expr);
|
||||
if (fval < 0.0 || (flags & FPLUS))
|
||||
need++;
|
||||
if ((flags & FWIDTH) && need < width)
|
||||
need = width;
|
||||
|
||||
CHECK(need);
|
||||
sprintf(&buf[blen], "%*s", need, "");
|
||||
if (flags & FMINUS) {
|
||||
if (fval < 0.0)
|
||||
buf[blen++] = '-';
|
||||
else if (flags & FPLUS)
|
||||
buf[blen++] = '+';
|
||||
strncpy(&buf[blen], expr, strlen(expr));
|
||||
}
|
||||
else {
|
||||
if (fval < 0.0)
|
||||
buf[blen + need - strlen(expr) - 1] = '-';
|
||||
else if (flags & FPLUS)
|
||||
buf[blen + need - strlen(expr) - 1] = '+';
|
||||
strncpy(&buf[blen + need - strlen(expr)], expr,
|
||||
strlen(expr));
|
||||
}
|
||||
blen += strlen(&buf[blen]);
|
||||
break;
|
||||
}
|
||||
|
||||
fmt_setup(fbuf, *p, flags, width, prec);
|
||||
need = 0;
|
||||
if (*p != 'e' && *p != 'E') {
|
||||
|
|
Loading…
Reference in a new issue