Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.lightlink.com!news.ripco.com!news.glorb.com!news-xfer.nntp.sonic.net!posts.news.sonic.net!nnrp1.nntp.sonic.net!not-for-mail Message-ID: <4E61B30F.5020508@bitblocks.com> Date: Fri, 02 Sep 2011 21:54:39 -0700 From: Bakul Shah User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 Newsgroups: comp.arch,alt.folklore.computers Subject: Re: Solving the Floating-Point Goldilocks Problem! References: <1319.297T1386T264355@kltpzyxm.invalid> <4E60C6B7.40309@SPAM.comp-arch.net> <8ht167tjg1dg9e22ekkf46dhfud0am962g@4ax.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Lines: 74 Organization: Sonic.Net NNTP-Posting-Date: 03 Sep 2011 04:54:39 GMT NNTP-Posting-Host: 3a3a0f6f.news.sonic.net X-Trace: DXC=mKZCbGBKXJfbL]PFGbQ>Rim4K\QM1CV^`1OYf0H`?;XaBDO5ZZ4GclcU[Zjk:d[l;fmcUHB?Tn3k` X-Complaints-To: abuse@sonic.net Xref: x330-a1.tempe.blueboxinc.net comp.arch:3402 On 9/2/11 12:08 PM, Stephen Fuld wrote: > On 9/2/2011 8:46 AM, Robert Wessel wrote: > > snip > >> But I've always though that some additional formatting in printf >> formatting strings would be an obvious feature to add to C. Checkout plan9's fmtinstall(). Allows you to provide your own formatting functions. For instance, in the example below %X is added to print a user defined type. typedef struct { double r, i; } Complex; int Xfmt(Fmt *f) { Complex c; c = va_arg(f–>args, Complex); return fmtprint(f, "(%g,%g)", c.r, c.i); } main(...) { Complex x = (Complex){ 1.5, –2.3 }; fmtinstall('X', Xfmt); print("x = %X\n", x); } > > > Yes, of course. While the full functionality of picture clauses might be nice, A small subset would > go a long way. The single thing I would most like to see is to make it easy to print numbers with > separators every three characters. I get so frustrated when I see things like the output of a > profiling program say a routine was executed > > 34587706689349 times. > > It sure makes it hard to read and there is no excuse for that. I realize there are issues with > commas versus spaces as separators, but these could be overcome. I would like to see the "digit > separated" format be another editing code so it would be trivial for a programmer to specify it > without having to create a full picture clause, which would be many more characters to input and > thus less frequently used. > > The second most useful feature I suspect would be a floating currency indicator. Once you get beyond > those two, I think the utility falls off pretty quickly, though the ability to specify that negative > values should be a different color might be nice. But I suspect that say the ability to have CR or > DB automatically appended to the value depending on sign is pretty unimportant. > > But digit separators would help in a lot of places. Ansi C has now has a ' (single quote) flag which prints a number in a locale specific manner. For instance (on Linux): $ cat xx.c #include #include main(int argc, char** argv) { setlocale(LC_ALL, argv[1]); printf("%'f\n", 34587706689349.125); } $ cc xx.c $ a.out en_DK 34.587.706.689.349,125000 $ a.out en_GB 34,587,706,689,349.125000 $ a.out en_IN 3,45,87,70,66,89,349.125000 Of course, the challenge is in making programmers use this!