summaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-22 03:25:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-22 03:25:14 +0000
commit3bad2b6ed996aaf9795b1c0f0fa92124a74226c1 (patch)
tree59cbdd22e1170790faa5b1439e9b113765ff513c /missing
parent941e77dc91669f433604c33615d5764a01f3ac92 (diff)
* missing/vsnprintf.c (BSD_vfprintf): fix for test_sprintf_comb.rb, by
wanabe in [ruby-dev:36935]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'missing')
-rw-r--r--missing/vsnprintf.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c
index c4326b4634..1ea2f143c2 100644
--- a/missing/vsnprintf.c
+++ b/missing/vsnprintf.c
@@ -753,6 +753,8 @@ reswitch: switch (ch) {
#ifdef FLOATING_POINT
case 'e': /* anomalous precision */
case 'E':
+ if (prec != 0)
+ flags |= ALT;
prec = (prec == -1) ?
DEFPREC + 1 : prec + 1;
/* FALLTHROUGH */
@@ -782,7 +784,7 @@ fp_begin: _double = va_arg(ap, double);
cp = cvt(_double, prec, flags, &softsign,
&expt, ch, &ndig);
if (ch == 'g' || ch == 'G') {
- if (expt <= -4 || expt > prec)
+ if (expt <= -4 || (expt > prec && expt > 1))
ch = (ch == 'g') ? 'e' : 'E';
else
ch = 'g';
@@ -798,6 +800,8 @@ fp_begin: _double = va_arg(ap, double);
size = expt;
if (prec || flags & ALT)
size += prec + 1;
+ } else if (!prec) { /* "0" */
+ size = 1;
} else /* "0.X" */
size = prec + 2;
} else if (expt >= ndig) { /* fixed g fmt */
@@ -1008,13 +1012,15 @@ number: if ((dprec = prec) >= 0)
if (ch >= 'f') { /* 'f' or 'g' */
if (_double == 0) {
/* kludge for __dtoa irregularity */
- if (prec == 0 ||
+ if (ndig <= 1 &&
(flags & ALT) == 0) {
PRINT("0", 1);
} else {
PRINT("0.", 2);
PAD(ndig - 1, zeroes);
}
+ } else if (expt == 0 && ndig == 0 && (flags & ALT) == 0) {
+ PRINT("0", 1);
} else if (expt <= 0) {
PRINT("0.", 2);
PAD(-expt, zeroes);