diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-20 01:03:18 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-20 01:03:18 +0000 |
commit | e9240114a0e8114823c9d0227b4315f71349828c (patch) | |
tree | 3fd21858916d79bcf25883e1330d508bef8a48a9 | |
parent | fb796561f0b601148c7b242ad1a3e847ef60e3c9 (diff) | |
download | ruby-e9240114a0e8114823c9d0227b4315f71349828c.tar.gz |
* vsnprintf.c (BSD_vfprintf): print floating point on "%#a".
[ruby-dev:42431] Bug#3965
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_sprintf.rb | 9 | ||||
-rw-r--r-- | vsnprintf.c | 7 |
3 files changed, 14 insertions, 7 deletions
@@ -1,3 +1,8 @@ +Wed Oct 20 10:00:57 2010 NARUSE, Yui <naruse@ruby-lang.org> + + * vsnprintf.c (BSD_vfprintf): print floating point on "%#a". + [ruby-dev:42431] Bug#3965 + Tue Oct 19 19:30:11 2010 NARUSE, Yui <naruse@ruby-lang.org> * vsnprintf.c (BSD_vfprintf): clear ALT flag for %a. diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index 3919f70f7d..ad77df19b8 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -221,10 +221,15 @@ class TestSprintf < Test::Unit::TestCase assert_equal("-0x1.08p+0", sprintf("%010a", -1.03125), bug3962) bug3964 = '[ruby-core:32848]' - assert_equal("0x000000000000000p+0", sprintf("%020a", 0), bug3962) + assert_equal("0x000000000000000p+0", sprintf("%020a", 0), bug3964) assert_equal("0x000000000000001p+0", sprintf("%020a", 1), bug3964) assert_equal("-0x00000000000001p+0", sprintf("%020a", -1), bug3964) - assert_equal("0x000000000000000p+0", sprintf("%#020a", 0), bug3962) + assert_equal("0x00000000000000.p+0", sprintf("%#020a", 0), bug3964) + + bug3965 = '[ruby-dev:42431]' + assert_equal("0x1.p+0", sprintf("%#.0a", 1), bug3965) + assert_equal("0x00000000000000.p+0", sprintf("%#020a", 0), bug3965) + assert_equal("0x0000.0000000000p+0", sprintf("%#020.10a", 0), bug3965) end BSIZ = 120 diff --git a/vsnprintf.c b/vsnprintf.c index 1f4172efb8..88a36a102e 100644 --- a/vsnprintf.c +++ b/vsnprintf.c @@ -784,7 +784,6 @@ reswitch: switch (ch) { #ifdef FLOATING_POINT case 'a': case 'A': - flags &= ~ALT; if (prec >= 0) prec++; goto fp_begin; @@ -832,7 +831,7 @@ fp_begin: _double = va_arg(ap, double); expsize = exponent(expstr, expt, ch + 'p' - 'a'); ch += 'x' - 'a'; size = expsize + ndig; - if (ndig > 1) + if (ndig > 1 || flags & ALT) ++size; /* floating point */ } else if (ch <= 'e') { /* 'e' or 'E' fmt */ @@ -1067,7 +1066,7 @@ long_len: ox[2] = *cp++; ox[3] = '.'; PRINT(ox+2, 2); - PRINT(cp, ndig-1); + if (ndig > 0) PRINT(cp, ndig-1); } else /* XpYYY */ PRINT(cp, 1); PRINT(expstr, expsize); @@ -1179,8 +1178,6 @@ cvt(value, ndigits, flags, sign, decpt, ch, length, buf) *decpt = -ndigits + 1; bp += *decpt; } - if (value == 0) /* kludge for __dtoa irregularity */ - rve = bp; while (rve < bp) *rve++ = '0'; } |