
On Mon, Jan 28, 2013 at 02:06:48AM -0800, Simon Marlow wrote:
commit 63202b9df64041e1c17603ad5f06fec3c51f357d Author: Simon Marlow
Date: Mon Jan 28 09:38:06 2013 +0000 fix negative numbers for * modifiers (#7457)
---------------------------------------------------------------
Text/Printf.hs | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Text/Printf.hs b/Text/Printf.hs index 0546e84..6028e16 100644 --- a/Text/Printf.hs +++ b/Text/Printf.hs @@ -281,7 +281,7 @@ getSpecs l z s ('*':cs) us = in ((p', r), us''') '.':r -> (stoi 0 r, us') _ -> ((-1, cs), us') - in (n, p, l, z, s, cs'', us'') + in (abs n, p, if n < 0 then not l else l, z, s, cs'', us'') getSpecs l z s ('.':cs) us = let ((p, cs'), us') = case cs of
Hmm, this works for minBound for Int8:
> printf "%*sx\n" (-4 :: Int8) "hi"
hi x
> printf "%*sx\n" (minBound :: Int8) "hi"
hi x
but not Int:
> printf "%*sx\n" (-4 :: Int) "hi"
hi x
> printf "%*sx\n" (minBound :: Int) "hi"
hix
(the last line should have a huge number of spaces between "hi" and "x".
Actually, this matches what the printf commandline program does:
$ printf "%*sx\n" -4 hi
hi x
$ printf "%*sx\n" -2147483648 hi
hix
and C just doesn't print anything:
$ cat q.c
#include